1. Create a txt file and write the username to be created
[root@hya srcipts]# vim user.txt
hya110
hya120
hya130
2. Write the script
[root@hya srcipts]# vim 无交互改密.sh
#/usr/bin/env sh
for i in `cat user.txt`
do
useradd $i
echo "1234" | passwd --stdin $i
done
[root@hya srcipts]# ./无交互改密.sh
更改用户 hya110 的密码 。
passwd:所有的身份验证令牌已经成功更新。
更改用户 hya120 的密码 。
passwd:所有的身份验证令牌已经成功更新。
更改用户 hya130 的密码 。
passwd:所有的身份验证令牌已经成功更新。
3. Delete users
[root@hya srcipts]# vim 删除普通用户脚本.sh
#!/bin/bash
for i in `cat user.txt`
do
userdel $i
rm -rf /home/$i
echo $i
done
我们来看txt有哪些用户
[root@hya srcipts]# cat user.txt
hya110
hya120
hya130
[root@hya srcipts]# sh 删除普通用户脚本.sh
hya110
hya120
hya130