Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ $USER != "root" ]
  4. then
  5. echo "Note: You are required to run this program as root."
  6. exit 1
  7. fi
  8.  
  9. if [ "$#" -eq 0 ] # if no arguments after command
  10. then
  11. echo "You must enter an argument" >&2
  12. echo "USAGE: $0 [-i {input-path}]" >&2
  13. exit 2
  14. fi
  15.  
  16. outputFlag="n"
  17. while getopts i: name
  18. do
  19. case $name in
  20. i) inputFile=$OPTARG ;;
  21. :) echo "Error: You need text after options requiring text"
  22. exit 1 ;;
  23. ?) echo "Error: Incorrect option"
  24. exit 1 ;;
  25. esac
  26. done
  27.  
  28. if [ ! -f $inputFile ]
  29. then
  30. echo "The file pathname "$inputFile" is empty or does not exist" >&2
  31. exit 2
  32. fi
  33.  
  34. set $(sed 's/ /+/g' $inputFile) # temporarily convert spaces to + for storing lines as positional parameters
  35.  
  36. for x
  37. do
  38. userPassWd=$(date | md5sum | cut -d" " -f1)
  39. useradd -m -c "$(echo $x | cut -d":" -f2 | sed 's/+/ /g')" -p $userPassWd $(echo $x | cut -d":" -f1)
  40. mail -s "Server Account Information" $(echo $x | cut -d":" -f3) <<+
  41. Here is your server account information:
  42. servername: placeholder.servername.on.ca
  43. username: $(echo $x | cut -d":" -f1)
  44. password: $userPassWd
  45. Regards,
  46. IT Department
  47. +
  48. done
  49.  
  50. echo -e "nnAccounts have been creatednn"
  51. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement