KIT501 Assignment 2
KIT501 ICT Systems Administration Fundamentals Semester 2, 2018
Assignment Two – UNIX Shell Programming
(10% of your KIT501 final result)
Due at 3pm Thursday Week 12, 11th October 2018
There are three (3) shell programming tasks in this assignment. This is an individual assignment. You are required to make a directory named KIT501a2 under your home directory (on alacritas), and use KIT501a2 as your working directory for this assignment.
Assignment submissions will be marked on alacritas. If you write and test your scripts elsewhere it’s your responsibility to ensure that your scripts run correctly on the School UNIX system (alacritas). If your scripts do not run on alacritas, they will receive zero marks immediately.
Task A
Write a shell script (to run on the Bourne shell) that takes a file name as argument and then compresses and decompresses the file with each of the following programs:
bzip2 gzip zip
For each of the compressing programs, the script notes the size of the file before and after compression. Then, the script displays a table showing the compression program, uncompressed size, and compressed size. Before using a compressing program to manipulate the file, your script must verify that the file actually exists under the current directory and is readable.
Your script for this task must be named compr.sh. Make sure your script is user- friendly and follows common sense. Your script must generate an output similar to the sample output shown below (The $ is the shell prompt, and ff is the file name):
(Note: This output shows that, before compressing, the size of the file named ff is 174145 bytes. After compressing using bzip2, its size becomes 13976 bytes. After compressing using gzip, its size becomes 11746 bytes. After compressing using zip, its size becomes 11879 bytes. The table shows that, for file ff, the most efficient compressing program is gzip. Please note that the columns of the table must be left-aligned.)
$ compr.sh ff
File: ff bzip2 174145 13976 gzip 174145 11746 zip 174145 11879
Page 1 of 6
Task B
KIT501 Assignment 2
Write a shell script (to run on the Bourne shell) that runs an infinite loop to check every 3 seconds to report on who logs into and who logs out of a UNIX system. Without loss of practical significance of this little utility, we can ignore multiple logins from the same user during a time period of less than 3 seconds.
You would need to research some of these UNIX commands: cut, sort, cmp.
Your script for this task must be named log.sh. The following is a sample output of the script (It is OK that the script leaves behind a temporary file when it is finally interrupted). The $ is the shell prompt.
$ log.sh
The current time is: Tue August 24 12:18:28 EST 2018
The current users are: abc rv0 sxu
tgray
No user has logged in/out in the last 3 seconds.
No user has logged in/out in the last 3 seconds.
User rsmith has logged in. User jchen has logged in.
No user has logged in/out in the last 3 seconds.
User abc has logged out. User rv0 has logged out.
No user has logged in/out in the last 3 seconds. … … … …… … … …
(Note: The second line of the output must show the current time when this script is run.)
Page 2 of 6
Task C
KIT501 Assignment 2
A telephone directory file, teledir.txt, maintains records in the form: name:number
where number is of the form xxxxxxxx. The following is an example of such telephone directory file:
Devise a shell script (to run on the Bourne shell) that accepts one argument which could be a name or a phone number. If it exists in the telephone file, then the entry should be displayed.
A validation check for the name or the number has to be performed. A valid name can contain only letters and spaces. A valid phone number must contain 8 digits, and the first digit of a valid phone number must not be zero. In the beginning of your script you need to verify that the telephone directory file (teledir.txt)actually exists under the current directory.
Your script for this task must be named phone.sh. Here are sample outputs of your script. The $ is the shell prompt.
John Smith:63243333 Sally Williams:62269988 Dan Roberts:63365577 Ray Jackson:62278989
$ phone.sh john
John Smith:63243333
$ phone.sh Smith
John Smith:63243333
$ phone.sh “John Smith”
John Smith:63243333
$ phone.sh 62269988
Sally Williams:62269988
$ phone.sh Adams
Name does not exist
$ phone.sh 99999999
Number does not exist
$ phone.sh 09999999
Invalid phone number
$ phone.sh 123456789
Invalid phone number
$ phone.sh Smith1
Invalid name
Page 3 of 6
For All Your Scripts
You must
- Include your full name, student ID, and a brief introduction of what the
script does in all your shell scripts, as a comment in the beginning of each
script.
- Make your scripts run on the Bourne shell, regardless of which shell the user
of your scripts is currently on.
- Add in-line comments to help other people understand your scripts.
- Use “\n” where appropriate to make the output of your scripts more
readable.
- Note that your script structure and layout are also important as they will be
marked as part of the assessment process.
Submitting Your Assignment
You must submit a single folder named KIT501a2 which contains the following five (5) files, electronically to the KIT501submit folder which has been created for you in your alacritas account:
compr.sh log.sh phone.sh ff teledir.txt
(Please make sure that your KIT501a2 folder only contains the five files as listed here, when you are ready to submit them)You can use a Windows PC (in one of our school’s Windows PC labs) to submit your assignment. This can be done by simply selecting your assignment folder and copy it: In Windows, right-click on your KIT501a2 folder and choose copy from the pop-up context menu. Navigate to the KIT501submit folder (which is located in your alacritas account [M: drive in the school computer lab]), right-click on it, and choose paste from the pop-up menu. You should look in the KIT501submit folder to verify that your assignment files are there.
IMPORTANT NOTE: The KIT501submit folder will be created for you automatically close to the submission time – do not create it yourself as this may cause your assignment to not be submitted correctly. If the KIT501submit folder does not exist (or you accidently delete it), please visit the School Help Desk.
You must also submit a signed cover sheet to the KIT501 assignment box located at the School Help Desk or Reception. Assignments without a signed coversheet will NOT be marked.
Please note: It is your responsibility to ensure that your assignment has been successfully submitted to the correct folder on alacritas. If you require assistance with this please visit the School Help Desk.
If your assignment is late then you should submit your files to the KIT501late folder. The late folder will be created automatically after the due date and will be available for one week only.
KIT501 Assignment 2
Page 4 of 6
Need Help?
You are encouraged to seek assistance from your lecturer after you have seriously thought about the assignment. Please note that we can provide general advice, however, we will not help you write any code, nor will we help you debug.
(See next page for the assignment marking scheme)
KIT501 Assignment 2
Page 5 of 6
KIT501 Assignment 2
Appendix: KIT501 Assignment 2 Marking Scheme
Script compr.sh (for each item there are only 3 possible marks: 100% or 50% or 0%)
Item |
Mark |
Execution of the shell script |
2 |
Include name, ID, and brief introduction in all scripts |
2 |
Appropriate in-line comments |
2 |
Verify that the manipulated file actually exists under the current directory and is readable |
2 |
Obtain the size of the file before and after compression |
2 |
Correctly use bzip2, gzip, and zip to compress the file |
2 |
Correctly display an output table which shows the specified information |
2 |
The columns of the table are left-aligned as specified |
2 |
Script log.sh (for each item there are only 3 possible marks: 100% or 50% or 0%)
Item |
Mark |
Execution of the shell script |
2 |
Include name, ID, and brief introduction in all scripts |
2 |
Appropriate in-line comments |
2 |
Correctly set up infinite loop |
2 |
Display every 3 seconds “No user has logged in/out in the last 3 seconds.” when this is true |
2 |
Correctly report users who have logged in |
2 |
Correctly report users who have logged out |
2 |
Script phone.sh (for each item there are only 3 possible marks: 100% or 50% or 0%)
Item |
Mark |
Execution of the shell script |
2 |
Include name, ID, and brief introduction in all scripts |
2 |
Appropriate in-line comments |
2 |
Verify the existence of the manipulated telephone directory file |
2 |
Validation check for an 8-digit telephone number |
2 |
Validation check for a name |
2 |
Correctly display the entry when an existing valid name is supplied as an argument |
2 |
Correctly display the entry when an existing valid number is supplied as an argument |
2 |
Script is able to handle arguments which are full names (with double quotes) |
2 |
Others (for each item there are only 3 possible marks: 100% or 50% or 0%)
Assignment Total: /50
Mark |
|
Shell scripts structure and layout |
2 |
Page 6 of 6