需要批量增加用户,给学生使用!
#!/bin/sh user_info=user.txt useradd=/usr/sbin/useradd passwd=/usr/bin/passwd cut=/bin/cut while read lines do username=`echo $lines | $cut -f1 -d' '` password=`echo $lines | $cut -f2 -d' '` groupadd $username $useradd $username -g $username >/dev/null 2>&1 if [ $? -eq 0 ];then echo "$password" | $passwd --stdin $username >/dev/null 2>&1 echo -e "\033[32m create user:$username passwd:$password\033[0m" else echo -e "\033[1;31;40m This user exists, we are going to change this user password \033[0m" echo "$password" | $passwd --stdin $username >/dev/null 2>&1 chown -R $username:$username /home/$username #echo -e "\033[32m $username:$password update successful\033[0m" echo -e "\033[32m "update user:$username password:$password"\033[0m" chown -R $username:$username /home/$username fi done < $user_info
脚本会调用user.txt文件,里面对应用户和密码信息即可!
cat user.txt
user001 12345678
user002 12345678
user003 12345678
user004 12345678
user005 12345678
user006 12345678
user007 12345678
user008 12345678
user009 12345678
user010 12345678
转载请注明:梦绘设计 » Python/Shell » shell脚本批量增加和修改用户
版权声明
本站《作品展示》类文章均为原创,转载必须注明出处,技术分享类文章部分来源于网络,版权归原作者所有,若侵权请留言。