Changes

Jump to: navigation, search

OPS235 Lab 4 - CentOS7

959 bytes added, 19:28, 10 April 2015
no edit summary
::  esac
</code>
<ol><li value="6">Save your editing session, but remain in the text editor.</li><li>The code displayed below uses logic to exit the script if the input file does not exist. Command substitution is used to store each line of the input file as a positional parameter. There is one subtle problem here: The full names of the users contain spaces which can create havoc when trying to set each line as a separate positional parameter. In this case the sed command is used to convert spaces to plus signs (+), which will be converted back later. Finally, and then a '''for ''' loop (for each positional parameter) is used to create each account ('''useradd''') and mail the user their account information ('''mail'''). Add the following code:</li></ol>
<br>
<code style="color:#3366CC;font-family:courier;font-size:.9em;">
::if [ ! -f $inputFile ]
::then
::&nbsp; echo "The file pathname \"$inputFile\" is empty or does not exist" >&2
::&nbsp; exit 2
::fi
::&nbsp; set $(sed 's/ /+/g' $inputfile) # temporarily convert spaces to + for storing lines as positional parameters
::for x
::do
::&nbsp; useradd -m -c "$(echo $x | cut -d":" -f2 | sed 's/+/ /g')" -p $(date | md5sum | cut -d" " -f1) $(echo $x | cut -d":" -f1)
::&nbsp; mail -s "Server Account Information" $(echo $x | cut -d":" -f3) <<+
::Here is your server account information:
::servername: myserver.senecac.on.ca
::username: $userName
::password: $userPassword
::Regards,
::IT Department
::+
::done
 
::echo -e "\n\nAccounts have been created\n\n"
::exit 0
</code>
13,420
edits

Navigation menu