Shell Script Add user Delete user Delete file script implementation

Source: Internet
Author: User

#/bin/bash#debug=0add=0del=0rm=0while [$#-gt 0]docase $ in-v|-verbose] debug=1shift;; -H|--HELP) #帮助文档echo "' basename $ '--add list--del list-h|--help--rm list" Exit 0;; --add) #添加用户ADD =1adduser=$2shift 2;; --del) #删除用户DEL =1deluser=$2shift 2;; --RM) #删除文件RM = 1; Rmfile=$2shift 2;; *) echo "wrong" shift; Esacdoneif test $RM-eq 1;then# $RM = 1, the--RM command is selected, Rmfile is the required action file after--rm. For I in ' echo $RMFILE | Sed ' s/,//g ';d o#sed ' s/,//g ' or ' [email protected],@ @g ' will rmfile inside the ', ' remove, as you may delete multiple files. If Test-e $I; then#-e determines if the file exists, then-f is the generic file,-D is the directory file. [-F $I] && rm-r $I [-D $I] && rm-rf $I [$DEBUG-eq 1] && echo "Delete this file successfully" else[$DEBUG-eq 1] && Echo ' The file does not exist! ' Fi donefiif test $ADD-eq 1;thenfor I in ' echo $ADDUSER |  Sed ' s/,//g ';d OIF ID $I &>/dev/null;then[$DEBUG-eq 1] && echo "User name is $i user already exists and cannot be added as a new user" Elsesudo Useradd $I [$DEBUG-eq 1] && echo "New user $i Add Success" Fidonefiif test $DEL-eq 1;thenfor I in ' echo $DELUSER | Sed ' s/,//g ';d OIF ID $I &≫/dev/null;thensudo Userdel $I [$DEBUG-eq 1] && echo "Delete $i user Success" else[$DEBUG-eq 1] && echo "User $i not present, Cannot delete "Fidonefi

Shell Script Add user Delete user Delete file script implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.