==========================================================================================
#!/bin/bash
#
if [ ! $# -eq 1 ];then
echo ‘./user.sh --add|--del‘
exit 1
fi
case "$1" in
--add)
for i in {1..10}
do
if id user$i &>/dev/null ;then
echo "user$i is exists."
else
useradd user$i
echo "user$i" |passwd --stdin user$i &> /dev/null
echo "Add user user$i finished."
fi
done
;;
--del)
for i in {1..10}
do
if id user$i &>/dev/null ;then
echo "Delete user$i finished."
userdel -r user$i
else
echo "user$i is not found."
fi
done
;;
*)
echo ‘./user.sh --add|--del‘
esac
==========================================================================================
#!/bin/bash
if [ $# -lt 2 ];then
echo "Usage $0 --add user1,user2,user3|--del user1,user2,user3|--help"
exit 1
fi
if [ $1 == "--add" ];then
for I in `echo $2|sed ‘s/,/ /g‘`
do
if id $I &> /dev/null;then
echo "$I exists."
exit 9
else
useradd $I
echo $I |passwd --stdin $I &>/dev/null
echo "Add user $I finished."
fi
done
elif [ $1 == "--del" ];then
for I in `echo $2|sed ‘s/,/ /g‘`
do
if id $I &> /dev/null;then
userdel -r $I
echo "Delete user $I finished."
else
echo "No sush $I. "
exit 9
fi
done
elif [ $1 == "--help" ];then
echo "Usage $0 --add user1,user2,user3|--del user1,user2,user3|--help"
else
echo "Usage $0 --add user1,user2,user3|--del user1,user2,user3|--help"
fi
批量添加或删除用户