Shell script to add a user to delete a user's deleted files
[Cpp] view plaincopy
- #/Bin/bash
- #
- DEBUG = 0
- ADD = 0
- DEL = 0
- RM = 0
- While [$ #-gt0]
- Do
- Case $ 1in
- -V |-verbose)
- DEBUG = 1
- Shift
- ;;
- -H | -- help)
- # Help documentation
- Echo "'basename $ 0' -- addLIST -- delLIST-h | -- help -- rmLIST"
- Exit0
- ;;
- -- Add)
- # Add a user
- ADD = 1
- ADDUSER = $2
- Shift2
- ;;
- -- Del)
- # Deleting a user
- DEL = 1
- DELUSER = $2
- Shift2
- ;;
- -- Rm)
- # Deleting an object
- RM = 1;
- RMFILE = $2
- Shift2
- ;;
- *)
- Echo "wrong"
- Shift
- ;;
- Esac
- Done
- Iftest $ RM-eq1; then
- # $ RM = 1, select the -- rm command, and RMFILE is the file to be operated after -- rm.
- ForIin 'echo $ RMFILE | sed's/, // g''; do
- # Sed's/, // G' or's @, @ G' remove "," From RMFILE, because you may delete multiple files.
- Iftest-e $ I; then
- #-E determines whether the file exists.-f indicates a general file and-d indicates a directory file.
- [-F $ I] & rm-r$ I
- [-D $ I] & rm-rf $ I
- [$ DEBUG-eq1] & echo "deleting this file successful"
- Else
- [$ DEBUG-eq1] & echo 'the file does not exist! '
- Fi
- Done
- Fi
- Iftest $ ADD-eq1; then
- ForIin 'echo $ ADDUSER | sed's/, // g''; do
- Ifid $ I &>/dev/null; then
- [$ DEBUG-eq1] & echo "the user whose username is $ I already exists and cannot be added as a new user"
- Else
- Sudouseradd $ I
- [$ DEBUG-eq1] & echo "new user $ I added successfully"
- Fi
- Done
- Fi
- Iftest $ DEL-eq1; then
- ForIin 'echo $ DELUSER | sed's/, // g''; do
- Ifid $ I &>/dev/null; then
- Sudouserdel $ I
- [$ DEBUG-eq1] & echo "deleting $ I user successful"
- Else
- [$ DEBUG-eq1] & echo "User $ I does not exist and cannot be deleted"
- Fi
- Done
- Fi