写了个可以添加多用户,删除多用户的小脚本,用户之间用空格隔开就可以,下面直接上代码:
#!/bin/bash
#discription:This file can add users or delete users.
#author:Zhai
#version:0.1
read -p "You want to add users or delete users,please choose (add|delete|quit):" choose
Choose=`echo $choose | tr ‘A-Z‘ ‘a-z‘`
case $Choose in
a|add|ad)
#add users
read -p "who do you want useradd :" adduser
for add in `echo "$adduser" | egrep -o "[[:alnum:]]+"`
do
if id $add &> /dev/null;then
echo "user `echo -e "\033[31m"$add"\033[0m"` does exist" && id $add
else
useradd $add &> /dev/null && echo "Add user `echo -e "\033[31m"$add"\033[0m"`" && id $add
fi
done
exit
;;
d|delete|de|del|dele|delet)
#delete users
read -p "who do you want userdel :" user
for del in `echo "$user" | egrep -o "[[:alnum:]]+"`
do
if id $del &> /dev/null;then
userdel -r $del &> /dev/null && echo "userdel `echo -e "\033[35m"$del"\033[0m"`"
else
echo "No user:`echo -e "\033[33m"$user"\033[0m"`"
fi
done
exit
;;
q|quit|qu|qui)
exit
;;
*)
echo "Your choose error!" && $0 #此处用$0,脚本不退出,从新使用脚本
;;
esac
脚本测试图