添加用户脚本
function main(){
for i in {1..20}
do
username=user$i
passwd="user`cat /dev/random | head -1 | md5sum | head -c 5`"
useradd $username
echo "$username:$passwd" | passwd --stdin $username
echo "$username--$passwd" >> user.txt
done
}
main @
执行结果
用户信息存储
因为只是在自己虚拟机上测试用的,测完之后再写个脚本把那些用户删掉
#! /bin/bash
function main(){
users=`cat /etc/passwd | grep "^user" |awk -F ":" '{print $1}'`
for user in $users
do
userdel -r $user
ret=$?
if [ $ret -eq 0 ];then
echo "delete $user successful"
else
echo "delete $user failed"
fi
done
cat /etc/passwd | grep "^user" |awk -F ":" '{print $1}' &>> /dev/null
if [ $? -eq 0 ];then
echo "delete users successful"
else
echo "delete users failed"
fi
}
main @
删除用户脚本执行结果