Pureftpd帐号管理脚本

#!/bin/bash
#
#
# functions: Pureftpd  script
# author: Hu ShuangFeng
# version 1.0: 2010-08-10.
#

FTP=/usr/local/pureftpd/bin/pure-pw
mkpasswd=`mkpasswd -l 22 -d 5 -C 5 > /tmp/pureftpdoo`
passwd1=`sed '1 w  /tmp/pureftpdoo1'  /tmp/pureftpdoo`
passwd2=`cat /tmp/pureftpdoo >> /tmp/pureftpdoo1`
passwd=/tmp/pureftpdoo1

while echo "==================================="
do
    printf  "What Are You Doing? /n /n1:UserAdd /n2:UserMod    /n3:UserPasswd    /n4:UserDel    /n5:ListAllUser    /n6:ListOneUser    /n7:List And Delete User /n8:ShowUser    /nq:Exit /n /n===================================/nEnter number: " ; read number
    while [ "$number" != "1" ]&&[ "$number" != "2" ]&&[ "$number" != "3" ]&&[ "$number" != "4" ]&&[ "$number" != "5" ]&&[ "$number" != "6" ]&&[ "$number" != "q" ]&&[ "$number" != "7" ]&&[ "$number" != "8" ]&&[ "$number" != "9" ]&&[ "$number" != " " ]
        do
            printf "Please enter the correct option :" ; read number
        done

    case "$number" in
    1)
        printf "Please Enter a user name :"  ; read name
        printf "/nYou directory is [`pwd`] ? /nPlease confirm /"yes/" or /"no/" :" ; read dddd
        while [ "$dddd" != "yes" ]&&[ "$dddd" != "no" ]&&[ "$dddd" != "y" ]&&[ "$dddd" != "n" ]&&[ "$dddd" != " " ]
                        do
                                printf "Please enter the correct option /"yes/" or /"no/" :" ; read dddd
                        done
                case  "$dddd"  in
                        y)
                $FTP useradd  $name -u nobody -g nobody -d `pwd`  -m < $passwd
                echo "-----------------------------------"
                echo " "
                echo "Users [$name] create successful ! "
                echo " "
                printf "You user name is : $name /n"
                printf "You Password is : $passwd1 /n"
                printf "You directory is : `pwd` /n"
                echo " "
                                ;;
                        yes)
                $FTP useradd  $name -u nobody -g nobody -d `pwd`  -m < $passwd
                echo "-----------------------------------"
                echo " "
                echo "Users [$name] create successful ! "
                echo " "
                printf "You user name is : $name /n"
                printf "You Password is : $passwd1 /n"
                printf "You directory is : `pwd` /n"
                echo " "
                                ;;
            n)
                printf "Please enter the directory : " ; read directory
                while  [ `echo "$directory" | grep  "^/"   |wc  -l` != "1" ]
                do
                    printf "Please enter the correct directory:" ; read directory
                done
                            $FTP useradd  $name -u nobody -g nobody -d $directory -m < $passwd
                            echo "-----------------------------------"
                            echo " "
                            echo "Users [$name] create successful !"
                            echo " "
                            printf "You user name is : $name /n"
                            printf "You Password is : $passwd1 /n"
                            printf "You directory is : $directory /n"
                            echo " "
                        ;;
            no)
                printf "Please enter the directory : " ; read directory
                while  [ `echo "$directory" | grep  "^/"   |wc  -l` != "1" ]
                do
                    printf "Please enter the correct directory:" ; read directory
                done
                            $FTP useradd  $name -u nobody -g nobody -d $directory -m < $passwd
                            echo "-----------------------------------"
                            echo " "
                            echo "Users [$name] create successful !"
                            echo " "
                            printf "You user name is : $name /n"
                            printf "You Password is : $passwd1 /n"
                            printf "You directory is : $directory /n"
                            echo " "
                        ;;
                esac
                ;;
    2)
        printf "Please enter a user name :"  ; read name
        printf "Please enter a new directory :"    ; read newdirectory
        $FTP usermod $name -u nobody -g nobody -d $newdirectory -m
        echo "-----------------------------------"
        echo " "
        echo "User [$name] modify a successful !"
        echo " "
        printf "You user name is : $name /n"
        printf "You new directory is : $newdirectory /n"
        echo " "
        ;;
    3)
        printf "Please enter a user name :"  ; read name
        $FTP passwd $name -m < $passwd
        echo "-----------------------------------"
        echo " "
        echo "[$name] Password changed successfully !"
        echo " "
        printf "You user name is : $name /n"
        printf "You nwe password is : $passwd1 /n"
        echo " "
        ;;
    4)
        printf "Please enter a user name :"  ; read name
        $FTP userdel $name -m
        echo "-----------------------------------"
               echo " "
        printf "You want to delete [$name]? /n /n/"yes/" or /"no/" : "  ; read yesno
            while [ "$yesno" != "yes" ]&&[ "$yesno" != "no" ]&&[ "$yesno" != "y" ]&&[ "$yesno" != "n" ]
                       do
                            printf "Please enter the correct option /"yes/" or /"no/" :" ; read yesno
                    done
                   case  "$yesno"  in
            y)
                $FTP userdel $name -m
                       echo "-----------------------------------"
                       echo " "
                       echo "Users [$name] have been deleted !"
                echo " "
                ;;
            yes)
                                   $FTP userdel $name -m
                                  echo "-----------------------------------"
                                 echo " "
                                echo "Users [$name] have been deleted !"
                               echo " "
                              ;;      
            esac
                    ;;
    5)
                $FTP list
                ;;
    6)   
        printf "Please enter a user name :"  ; read name
        $FTP list | grep $name
        echo " "
        ;; 
    7)   
        printf "Please enter a user name :"  ; read name
        $FTP list | grep $name
        echo "-----------------------------------"
               echo " "
        printf "You want to delete [$name]? /n /n/"yes/" or /"no/" : "  ; read yesno
            while [ "$yesno" != "yes" ]&&[ "$yesno" != "no" ]&&[ "$yesno" != "y" ]&&[ "$yesno" != "n" ]
                       do
                            printf "Please enter the correct option /"yes/" or /"no/" :" ; read yesno
                    done
                   case  "$yesno"  in
            y)
                $FTP userdel $name -m
                       echo "-----------------------------------"
                       echo " "
                       echo "Users [$name] have been deleted !"
                echo " "
                ;;
            yes)
                                   $FTP userdel $name -m
                                  echo "-----------------------------------"
                                 echo " "
                                echo "Users [$name] have been deleted !"
                               echo " "
                              ;;      
            esac
                    ;;

    8)   
        printf "Please enter a user name :"  ; read name
        $FTP show  $name
        echo " "
        ;;
    q)   
        exit
        ;; 
    esac

done

你可能感兴趣的:(Pureftpd帐号管理脚本)