Shell 编程(三)
创建一个脚本 admin.sh
完成如下作用:
-h | --help : 提供帮助信息
--add Users : 完成用户添加
-del User | --delete : 完成用户删除
-v : 开启调试模式,显示信息
可以同时使用以上所有命令
#!/bin/bash # DEBUG=0 ADD=0 DELETE=0 for i in `seq 1 $#` do case $1 in -h|--help) echo "--v --help --add --delete --userlist" ;; -v|--versbo) DEBUG=1 shift ;; --add) ADD=1 ADDUSERS=`echo $2 | sed 's@,@ @g'` shift 2 ;; -del|--delete) DELETE=1 DELETEUSERS=`echo $2 | sed 's@,@ @g'` shift 2 ;; *) # echo 'Usage : `basename $0` --add USERLIST --delete USERLIST --v|--verbose --help' # exit 7 ;; esac done if [ $ADD -eq 1 ] then for USER in $ADDUSERS do if id $USER &> /dev/null then [ $DEBUG -eq 1 ] && echo "$USER is exists!" else useradd $USER [ $DEBUG -eq 1 ] && echo "$USER add succefully!" fi done fi if [ $DELETE -eq 1 ] then for USER in $DELETEUSERS do if id $USER &> /dev/null then userdel $USER [ $DEBUG -eq 1 ] && echo "$USER delete successfully!" else [ $DEBUG -eq 1 ] && echo "$USER not exist!" fi done fi
相关推荐
tianhuak 2020-11-24
woaimeinuo 2020-10-21
touchfuture 2020-09-16
huha 2020-10-16
laisean 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
JohnYork 2020-10-16
Julyth 2020-10-16
applecarelte 2020-10-16
laisean 2020-09-27
flycappuccino 2020-09-27
liguojia 2020-09-27
wangzhaotongalex 2020-09-22
流年浅滩 2020-10-23
liujianhua 2020-10-22
tufeiax 2020-09-03
laisean 2020-09-01
vvu 2020-09-16
libao 2020-09-16
Yyqingmofeige 2020-08-18
zhushixia 2020-08-17