Shell script to add a user to delete a user's deleted files
#/Bin/bash # DEBUG = 0ADD = 0DEL = 0RM = 0 while [$ #-gt 0] docase $1 in-v |-verbose) DEBUG = 1 shift ;; -h | -- help) # help document echo "'basename $ 0' -- add LIST -- del LIST-h | -- help -- rm LIST" exit 0; -- add) # ADD User ADD = 1 ADDUSER = $2 shift 2; -- del) # delete user DEL = 1 DELUSER = $2 shift 2; -- rm) # delete a file RM = 1; RMFILE = $2 shift 2; *) echo "wrong" shift; esacdoneif test $ RM-eq 1; then # $ RM = 1, select the -- rm command, and RMFILE is the file to be operated after -- rm. For I in 'echo $ RMFILE | sed's/, // g''; do # sed's/, // G' or's @, @ G' remove "," From RMFILE because you may delete multiple files. If test-e $ I; then #-e checks whether the file exists, then-f indicates a general file, and-d indicates a directory file. [-F $ I] & rm-r $ I [-d $ I] & rm-rf $ I [$ DEBUG-eq 1] & echo "delete this file successful "else [$ DEBUG-eq 1] & echo 'This file does not exist! 'Fi donefiif test $ ADD-eq 1; thenfor I in 'echo $ ADDUSER | sed's/, // g''; doif id $ I &>/dev/null; then [$ DEBUG-eq 1] & echo "the user name $ I already exists, cannot be added as new user "elsesudo useradd $ I [$ DEBUG-eq 1] & echo" new user $ I added successfully "fidonefiif test $ DEL-eq 1; thenfor I in 'echo $ DELUSER | sed's/, // g''; doif id $ I &>/dev/null; thensudo userdel $ I [$ DEBUG-eq 1] & echo "I user deleted successfully" else [$ DEBUG-eq 1] & echo "User $ I does not exist, "fidonefi" cannot be deleted