SYST13416 – Linux Assignment Help

Your assignment will be working with the phonebook file. Out of country students without access to Atlas will need to install Ubuntu or other Linux on a VM on their desktop and email me for instructions.

Make a subdirectory of your home/SYST13416 called “assignment” and then make it your pwd.

In the  assignment directory make a file called “assign”. This will be your assignment shell script. Ensure others cannot read this file, remove the r permission for group.

Copy the phonebook file from /tmp/phonebook so it is in your pwd. Create a backup of it, call it phonebook.bk.

Copy /tmp/appendfile so it is in your pwd. The file looks as follows:

Edit the file using vi so that your first name and last name replace the FNAME LNAME text. You may need to change the security setting to do this.

Now, edit the script assign to do the following scenarios. You will find it works best if you do it iteratively, not all at once. DO one function at a time, test it/debug and fix it and then move to next:

  1. If you simply call the script without any parameters, it will ask the user for the LAST name of the person to pull the information for. You will display this record and exit the shell script with return code 1. If you do not find the record, provide an error message and such as “This Last Name was not found, sorry” and exit the script with return code 2.
  2. If you call the script with option -f , then this means the script will prompt the user for the FIRST name of the person you are looking for. If you find that person, display ONLY their phone extension (hint, use cut command). Exit with return code 3.
  3. If the script has option -c, then the system will make a campus phonebook for the user. It will prompt the user for the campus code such as NH. Look carefully where that campus code is in the file and create a regex that matches it. Your script will find all the people in that campus and create a file with the name of the So, for NH it would be Put this file in your pwd, but create a link to it which you put in your /tmp/`whoami` directory (the whoami is replaced by your username).
  4. If the script uses option -a, then prompt the user for a filename and then append that file to the phonebook. This will be used to add yours and my record to the phonebook. Then, exit the script.
  5. Otherwise, for each separate word that is passed to the script as a positional parameter, search for that regex int the file and append the records to a file you will call result. If you don’t find the name, add a line to result indicating that you could not find it.

After you are done with the script, create a link to the file result and put in your /tmp/`whoami` directory.

Note: the code to run the regular expressions needed for this assignment is no more than standard grep. If you find yourself using extended regular expressions and/or awk, you are likely doing something more complicated than need be. Do not take code and copy code from someone else without knowing exactly how it works. You may be challenged by the instructor to explain your code. Not being able to explain code you wrote, would be automatic “F”.

To exercise your script, run the following commands, capture the screen images and submit this file into the drop box.

At a high level, here is the test for your script:

  1. bash assign               
  2. bash assign -f            
  3. bash assign -c           
  4. bash assign -a           
  5. bash assign Buchner Cheryl Joel Elvis <yourname>  


  • ignore case for your greps
  • be careful to embed your strings with “ “
  • Use $? To check return codes and determine if a command worked
  • Look at the phonebook file carefully (in vi?) to see how it is structured so that you can grep the correct pattern/regex
  • Use echo and read to write and read from terminal session
  • Use exit to exit a script. If you put a number after it, the value of the number will be $?. If not, $? will be 0. So ,exit 2 will return $? value of 2
  • Use cut to select fields or characters in the output
  • Use pipe to make more complicated filters
  • You can redirect or append your output

Details for your submission:

  1. bash assign
  2. Pangborn
  3. echo $? the result should be 2
  4. bash assign again
  5. Trudeau
  6. ype echo $? The result should be 1

It should look something like the following

  • bash assign -f

–    shell will prompt for a first name

–    enter the first name Mark

–    The system should only get phone numbers for persons with Mark (not city Markham or last name Markovski). The result should be something like the following. You are welcome to make it look better.

  • Next if you type echo $? The result should be 3.
  • Last, type whoami so I can see this is your screen

Take a screen shot of above steps and paste below.

  • bash assign -c
  • shell will tell you it is making a campus phonebook
  • enter     LE
  • the system will make a campus phonebook called
  • type ls and take a screen shot and paste it here
  • if you type cat, you will see only people in the LE campus (the second fields will only LE)
  • Type the command whoami so I can see this is your session
  • Take a screen shot of above steps and paste below.
  • bash assign -a
  • The system should prompt you for the name of the file you want to append
  • Type the filename appendfile (or whatever you called the file)

Take a screen shot of above steps and paste the result below

  • bash assign Buchner Cheryl Joel Elvis <yourname>

I would expect to see your name come up as a Linux Student along with mine, I would expect you not to find Elvis As per above, dump the contents of file “found” and provide a screenshot.

Give a Comment