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
[Cpp] view plaincopy

  1. #/Bin/bash
  2. #
  3. DEBUG = 0
  4. ADD = 0
  5. DEL = 0
  6. RM = 0
  7. While [$ #-gt0]
  8. Do
  9. Case $ 1in
  10. -V |-verbose)
  11. DEBUG = 1
  12. Shift
  13. ;;
  14. -H | -- help)
  15. # Help documentation
  16. Echo "'basename $ 0' -- addLIST -- delLIST-h | -- help -- rmLIST"
  17. Exit0
  18. ;;
  19. -- Add)
  20. # Add a user
  21. ADD = 1
  22. ADDUSER = $2
  23. Shift2
  24. ;;
  25. -- Del)
  26. # Deleting a user
  27. DEL = 1
  28. DELUSER = $2
  29. Shift2
  30. ;;
  31. -- Rm)
  32. # Deleting an object
  33. RM = 1;
  34. RMFILE = $2
  35. Shift2
  36. ;;
  37. *)
  38. Echo "wrong"
  39. Shift
  40. ;;
  41. Esac
  42. Done
  43. Iftest $ RM-eq1; then
  44. # $ RM = 1, select the -- rm command, and RMFILE is the file to be operated after -- rm.
  45. ForIin 'echo $ RMFILE | sed's/, // g''; do
  46. # Sed's/, // G' or's @, @ G' remove "," From RMFILE, because you may delete multiple files.
  47. Iftest-e $ I; then
  48. #-E determines whether the file exists.-f indicates a general file and-d indicates a directory file.
  49. [-F $ I] & rm-r$ I
  50. [-D $ I] & rm-rf $ I
  51. [$ DEBUG-eq1] & echo "deleting this file successful"
  52. Else
  53. [$ DEBUG-eq1] & echo 'the file does not exist! '
  54. Fi
  55. Done
  56. Fi
  57. Iftest $ ADD-eq1; then
  58. ForIin 'echo $ ADDUSER | sed's/, // g''; do
  59. Ifid $ I &>/dev/null; then
  60. [$ DEBUG-eq1] & echo "the user whose username is $ I already exists and cannot be added as a new user"
  61. Else
  62. Sudouseradd $ I
  63. [$ DEBUG-eq1] & echo "new user $ I added successfully"
  64. Fi
  65. Done
  66. Fi
  67. Iftest $ DEL-eq1; then
  68. ForIin 'echo $ DELUSER | sed's/, // g''; do
  69. Ifid $ I &>/dev/null; then
  70. Sudouserdel $ I
  71. [$ DEBUG-eq1] & echo "deleting $ I user successful"
  72. Else
  73. [$ DEBUG-eq1] & echo "User $ I does not exist and cannot be deleted"
  74. Fi
  75. Done
  76. Fi

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.