Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $USER != "root" ]
- then
- echo "Note: You are required to run this program as root."
- exit 1
- fi
- if [ "$#" -eq 0 ] # if no arguments after command
- then
- echo "You must enter an argument" >&2
- echo "USAGE: $0 [-i {input-path}]" >&2
- exit 2
- fi
- outputFlag="n"
- while getopts i: name
- do
- case $name in
- i) inputFile=$OPTARG ;;
- :) echo "Error: You need text after options requiring text"
- exit 1 ;;
- ?) echo "Error: Incorrect option"
- exit 1 ;;
- esac
- done
- if [ ! -f $inputFile ]
- then
- echo "The file pathname "$inputFile" is empty or does not exist" >&2
- exit 2
- fi
- set $(sed 's/ /+/g' $inputFile) # temporarily convert spaces to + for storing lines as positional parameters
- for x
- do
- userPassWd=$(date | md5sum | cut -d" " -f1)
- useradd -m -c "$(echo $x | cut -d":" -f2 | sed 's/+/ /g')" -p $userPassWd $(echo $x | cut -d":" -f1)
- mail -s "Server Account Information" $(echo $x | cut -d":" -f3) <<+
- Here is your server account information:
- servername: placeholder.servername.on.ca
- username: $(echo $x | cut -d":" -f1)
- password: $userPassWd
- Regards,
- IT Department
- +
- done
- echo -e "nnAccounts have been creatednn"
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement