#!/bin/bash
#输入add添加用户,输入del删除用户,-v选择是否显示结果信息
DEBUG=0
ADD=0
DEL=0
for i in `seq 0 $#`; do
if [ $# -gt 0 ];then
case $1 in
-v)
DEBUG=1
shift
;;
-h)
echo "please open the help page....."
exit 0
;;
--add)
ADD=1
ADDUSER=$2
shift 2
;;
--del)
DEL=1
DELUSER=$2
shift 2
;;
*)
echo -e "\e[1;31myou wrong....\e[0m"
exit 4
;;
esac
fi
done
echo "$DEBUG $ADD $DEL"
if [ $ADD -eq 1 ];then
for users in `echo "$ADDUSER" | sed ‘s/,/ /g‘`;do
if id $users &> /dev/null;then
[ $DEBUG -eq 1 ] && echo "$users exists."
else
useradd $users
[ $DEBUG -eq 1 ] && echo "$users add finished."
fi
done
fi
if [ $DEL -eq 1 ];then
for users in `echo "$DELUSER" | sed ‘s/,/ /g‘`;do
if id $users &> /dev/null;then
userdel -r $users
[ $DEBUG -eq 1 ] && echo "$users delete finished."
else
[ $DEBUG -eq 1 ] && echo "$users not exists."
fi
done
fi