实现文件中批量用户创建
创建用户文件
[root@localhost ~]# cat user.txt
user01
user02
user03
user04
user05
脚本案例
#!/bin/bash
#create user by file
#v1.0 itwangqiang 2020/12/28
pass=123456
if [ $# -eq 0 ];then
echo "usage: `basename $0` file"
exit
fi
if [ ! -f $1 ];then
echo "error file"
exit
fi
for user in `cat $1`
do
id $user &> /dev/null
if [ $? -eq 0 ];then
echo "user $user is exist"
else
useradd $user
echo "$pass" |passwd --stdin $user &> /dev/null
fi
done
执行
[root@localhost shell]# ./createuser.sh user.txt
user user01 is exist
user user02 is exist
user user03 is exist
user user04 is exist
user user05 is exist
[root@localhost shell]# ls /home/
user01 user02 user03 user04 user05