echo -n "创建用户输入C,删除用户输入D!" read name function monitor() { if [ "$name" == "C" ] || [ "$name" == "c" ];then function_create elif [ "$name" == "D" ] || [ "$name" == "d" ]; then function_rm else echo "Input Error" fi } function_create () { echo -n "输入用户名(英文全拼):" read USER_LIST #echo -n "输入用户邮箱:" #read MAIL_LIST echo -n "输入授权ip地址" read IP_LIST #DATE=$NAME USER_FILE=./user.txt for USER in $USER_LIST; do if ! id $USER &>/dev/null; then PASS=$(echo $RANDOM |md5sum |cut -c 1-8) useradd $USER echo $PASS |passwd --stdin $USER &>/dev/null echo "$USER $PASS" >> $USER_FILE echo "$USER User create successful." echo -n "输入用户邮箱:" read MAIL_LIST echo $MAIL_LIST for MAIL in $MAIL_LIST;do if ! $MAIL &>/dev/null; then echo "USR:$USER PWD:$PASS IP:$IP_LIST" |mail -s "monitor" $MAIL else echo "邮箱错误" fi done else echo "$USER User already exists!" fi done } #function_rm () #{ #echo 222 #} monitor
原文:https://www.cnblogs.com/Carr/p/10491493.html