腳本可能寫的還不太完善,目前能考慮到的有這麼三點:
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:"
read name
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
本文轉自 yuri_cto 51CTO部落格,原文連結:http://blog.51cto.com/laobaiv1/1838489,如需轉載請自行聯系原作者