Shell script to add a user to delete a user's deleted files

Source: Internet
Author: User

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

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.