The Problem
You are to write a Perl script that will read in values from an INPUT file to be passed as
an argument to the script. The file contains the following information:
o The user's full name (e.g., Mike H Smith)
o A period after Middle name is optional
o Full Middle name is also optional
o Assume there is always one space between First, Middle, and Last name
o You do NOT have to perform error checking on this field
o The user's ID number (ssno)
o Should be of the form: 3 digits, dash, 2 digits, dash, 4 digits
Ex: “111-22-3333”
o You DO have to perform error check on this field using string functions
mentioned in class. If the full social security number (the part between “/”)
is not of the right format you MUST print out the following message to STDERR: The String “Bad Soc” followed by a colon, then a space and the offending invalid Soc number. For Example:
Bad Soc: 123-456-7888
o Your error message must look EXACTLY like this, do not vary even slightly!
o You ONLY have to make sure that the dashes are in the correct places
and the number of characters is correct NOT that the other characters are
actually digits
o (DO NOT USE split() and REGULAR EXPRESSIONS for this)
o The user's group (will be “student”, “staff” ONLY)
o You do NOT need to perform error checking on this field
Based on this information, you will print to STDOUT a user line analogous to the one that would appear in /etc/passwd.
he INPUT file will be formatted as follows:
First Middle Last/SSN/Group
With the “/” character being used as the delimiter.
For example:
Morgn X. Zang/555-12-1234/staff
Mike Xavier Smith/123-45-1111/student
Susan y John/109-54-8832/student
Sarah Alex Zielewsky/987-65-4322/staff
Once you have the necessary input from the file, you need to create the following fields
to display to STDOUT:
username:passwd:uid:gid:full name:home dir path:shell
username:
o Create a old DCE style username for students: first initial, middle initial, last initial followed by last 4 of SSN (abc1234).
o Use just the 3 initials of the name for the username for staff (yxn)
o Note that there are NO uppercase letters in usernames
passwd:
In the modern age of password shadowing you would never really do this, but for the purpose of this lab you should allow the user to enter input for this value.
IMPORTANT: DO NOT PROMPT the user, they will just magically know to enter a string representing their password when the program just sits there waiting for something (the reason for this is so that the print out itself can be redirected to an
/etc/passwd-like file. Otherwise we would have to remove the prompts or redirect them separately.)
You can test this rather easily by creating a sample “input.txt” file, like the one shown above, and then have another file storing passwords (just make sure that you have the same number of lines in both).
You may run your program as:
$ example.pl input.txt < PASSWORDS
Redirecting STDIN to be read from a file, So that you don’t have to keep entering
passwords.
**** When you detect a bad SSN or a duplicate username do NOT read in from STDIN (and also do NOT generate a line of output with the bad input line).