- 批量创建用户
#!/bin/bash
# add_user.sh
if [ $# -eq 0 ];then
echo "你没有输入任何文件!"
exit 1
fi
if [ ! -f $1 ];then
echo "输入有误!"
exit 2
fi
for user in `cat user.txt`
do
id $user &>/dev/null
if [ $? -eq 0 ];then
echo "用户$user已存在!"
else
useradd $user
#echo "123" | passwd --stdin $user
echo $user:"123" | chpasswd
echo add $user success!
fi
done
- 批量删除用户
#!/bin/bash
# del_user.sh
if [ $# -eq 0 ];then
echo "你没有输入任何文件!"
exit 1
fi
if [ ! -f $1 ];then
echo "输入有误!"
exit 2
fi
for user in `cat $1`
do
id $user &>/dev/null
if [ $? -eq 0 ];then
userdel -rf $user &>/dev/null
echo "删除$user成功!"
else
echo "用户不存在!"
fi
done
- 例子
user.txt
user1
user2
user3
user4
image.png
image.png
网友评论