Create a script admin.sh
Perform the following functions:
-H | --HELP: Providing Help information
--add users: Completing user additions
-del User | --delete: Complete User deletion
-V: Turn on debug mode, display information
You can use all of the above commands at the same time
#!/bin/Bash#debug=0ADD=0DELETE=0 forIinch`seq 1 $#` Do Case$1 inch-h|--Help )Echo "--v--help--add--delete--userlist" ;;-v|--Versbo) DEBUG=1 Shift ;;--add) ADD=1addusers=`Echo$2|sed '[email protected],@ @g'` Shift 2 ;;-del|--Delete) DELETE=1deleteusers=`Echo$2|sed '[email protected],@ @g'` Shift 2 ;;*)# Echo 'Usage: ' basename $ '--add userlist--delete userlist --v|--verbose--help'# Exit7 ;;Esac Doneif[$ADD-eq1 ] Then forUSERinch$ADDUSERS Do if ID$USER &>/dev/NULL Then[$DEBUG-eq1] &&Echo "$USER is exists!" Elseuseradd $USER [$DEBUG-eq1] &&Echo "$USER Add succefully!" fi Donefiif[$DELETE-eq1 ] Then forUSERinch$DELETEUSERS Do if ID$USER &>/dev/NULL ThenUserdel $USER [$DEBUG-eq1] &&Echo "$USER Delete successfully!" Else[$DEBUG-eq1] &&Echo "$USER not exist!" fi Donefi
Shell Programming (III)