2312132145 发表于 2016-8-16 09:27:56

自动添加VSFTP服务器虚拟用户脚本

脚本可能写的还不太完善,目前能考虑到的有这么三点:
1、用户名和密码不能为空
2、用户名不能重复
3、当输入用户名正确而密码为空的时候,会自动将之前输入的用户也删除也就是说本次输入失败
4、备份每次修改的用户配置文件,并将保存文件打上时间戳

后面待改进的可以添加输入用户名和字符数量限制等功能

#!/bin/bash
time=`date +%Y%m%d%k%M`
bakfile="user_logn.bak$time"
cp /etc/vsftpd/user_login /etc/vsftpd/vsftpd_bak/$bakfile

echo -n "Enter you want add ftp user's name:"

readname   

if [ "$name" = "" ]; then

echo "The name can't be null"

exit 1

else

grep $name /etc/vsftpd/user_login > /dev/null

if [ $? -eq 0 ]; then

    echo "The user is exist"

exit 1

else

    echo $name >> /etc/vsftpd/user_login

       if[ $? -eq 0 ]; then
            echo "Add user successful!~"

         echo -n "Enter you want add ftp user's password:"

            read password

         if [ "$password" = "" ]; then
            echo "The password can't be null"
            sed -i '$d' /etc/vsftpd/user_login
                exit 1
            else
                  echo $password >> /etc/vsftpd/user_login
                   if[ $? -eq 0 ]; then
                     echo "Add password successful!~"
         db_load -T -t hash -f /etc/vsftpd/user_login/etc/vsftpd/user_login.db
                   mkdir /home/vsftp/$name
                   chown ftp_vuser:ftp_vuser /home/vsftp/$name
                   echo "you input name is $name"
                     echo "password is $password"
                     echo "Please Mind it!"
                  else
                        echo "password is failed,Please check your input"

                  fi

            fi

      else

            echo "Add is failed, Please check the user_login file"

      fi
    fi

fi

页: [1]
查看完整版本: 自动添加VSFTP服务器虚拟用户脚本