Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Write a script that accepts as an input parameter the path/name for an input

ID: 664304 • Letter: 1

Question

1)     Write a script that accepts as an input parameter the path/name for an input password file (either /etc/password or the sample provided). Check for the existence and non-zero size of the input file and re-prompt if not correct.

2)     Use the egrep command on an input password file- redirecting the result of the search to apasswordfile. Search for the patterns of cm325 and cm315 (or a set of patterns that are available to you) using the colon (:) as the delimiter. The result should be an intermediate file with just the rows with these two users.

3)     Use the cut command with -f to generate a file for columns 1, 5, 6, and 7, naming them logname, comment, home, and shellfile, respectively.

4)     Taking the logname file, edit it by adding 15 spaces to the end of each line. Cut the logname file with the -c option to produce a file that has only 15 columns on each line and redirect the output to a file named loganame15.

5)     Edit the comment file created above- placing at the beginning of each line the following text where ^ is a space: ^is the logname for^.

Explanation / Answer

Shell Script:

egrep "cm325|cm315|cm305|cm345|cm365"' -oP "^[^:]*" $fileName | cut -d':' > aPassWordFile

cut -f1 $fileName > logname

cut -f5 $fileName > comment

cut -f6 $fileName > home

cut -f7 $fileName > shellfile

for line in logname echo "               " > loganame15

' is the logname for ' $filename