标签:example delete std done 新建 use echo user ESS
若需要批量新建或者删除用户,可使用简单脚本操作。
首先新建 users.txt,将要新建或者删除的用户放进去,
1 andy 2 barry 3 carl 4 duke 5 eric 6 george 7 kim 8 mary
然后编写Example.sh,(新建用户)
1 then 2 echo "Already exists" 3 else 4 useradd $UNAME &> /dev/null 5 echo "$PASSWD" | passwd --stdin $UNAME &> /dev/null 6 if [ $? -eq 0 ] 7 then 8 echo "$UNAME , Create Success" 9 else 10 echo "$UNAME , Create Failure" 11 fi 12 fi 13 done
编写userdel.sh,(删除用户)
1 #!/bin/bash 2 for UNAME in `cat users.txt` 3 do 4 id $UNAME &> /dev/null 5 userdel $UNAME &> /dev/null 6 if [ $? -eq 0 ] 7 then 8 echo "$UNAME delete success" 9 else 10 echo "$UNAME ,not exist,deleted failed" 11 fi 12 done
最后运行即可。
标签:example delete std done 新建 use echo user ESS
原文地址:https://www.cnblogs.com/wangmengjun/p/10662302.html