4
answers
1
watching
228
views

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 campus.book. So, for NH it would be NH.book. 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   (5 marks)
  2. bash assign -f (5 marks)
  3. bash assign -c (5 marks)
  4. bash assign -a (5 marks)
  5. bash assign Buchner Cheryl Joel Elvis <yourname>   (10 marks)

Tips:

  • 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
  • shell will prompt for a last name
  • enter the last name Pangborn
  • type echo $? the result should be 2
  • type bash assign again
  • enter the last name Trudeau
  • Shell should present a message that it was not found
  • Type echo $? The result should be 1
  • Type whoami

It should look something like the following

 

 

  • Take a screen shot of above steps on your screen and paste below.

 

  1. 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.

 

 

 

  1. bash assign -c
  • shell will tell you it is making a campus phonebook
  • enter     LE
  • the system will make a campus phonebook called LE.book
  • type ls and take a screen shot and paste it here

 

 

 

 

 

  • if you type cat LE.book, 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.

 

 

 

 

 

  1. 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

 

 

  1. 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 screen shot.

 

Final Step:

Cut and paste the code for  your shell script here. I would like to see the code YOU wrote. I do not want screen shots of code.

TurnItIn is ON, and so I am not expecting you to submit your friends assignment. I may ask you to present your code to me via SLATE virtual classroom. This step is worth 20 marks.

Another way to submit the code for your shell script is to ftp it from the atlas server to your laptop and then submit it to the drop box directly as a .sh file. TO do that, you would install an FTP client on your laptop and then access your atlas account using [email protected].  Navigate your way to the directory contain the script and download it. It is best add extension .sh or .bash for it to work. You can now upload that file and add it as a second submission to the drop box. You will receive a bonus point if you do this. The process is similar to your webdev class where you have to upload .html files which you have developed on your laptop to your apache server.

 

 

 

 

 

 

For unlimited access to Homework Help, a Homework+ subscription is required.

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in
Already have an account? Log in
Avatar image
Read by 2 people
Already have an account? Log in
Avatar image
Read by 2 people
Already have an account? Log in

Related questions

Related Documents

Weekly leaderboard

Start filling in the gaps now
Log in