KIT501 Asignment 2
Page 1 of 6
KIT501 ICT Systems Administration Fundamentals
Semester 2, 2018
Asignment Two – UNIX Shell Programing
(10% of your KIT501 final result)
Due at 3pm Thursday Wek 12, 11th October 2018
There are thre (3) shel 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.
Asignment submisions wil be marked on alacritas. If you write and test your
scripts elsewhere it's your responsibility to ensure that your scripts run corectly on
the School UNIX system (alacritas). If your scripts do not run on alacritas,
they wil receive zero marks imediately.
Task A
Write a shel script. (to run on the Bourne shel) that takes a file name as argument
and then compreses and decompreses the file with each of the folowing programs:
bzip2 gzip zip
For each of the compresing programs, the script. notes the size of the file before and
after compresion. Then, the script. displays a table showing the compresion
program, uncompresed size, and compresed size. Before using a compresing
program to manipulate the file, your script. must verify that the file actually exists
under the curent directory and is readable.
Your script. for this task must be named compr.sh. Make sure your script. is user-
friendly and folows comon sense. Your script. must generate an output similar to
the sample output shown below (The $ is the shel prompt, and ff is the file name):
$ compr.sh ff
File: ff
bzip2 174145 13976
gzip 174145 11746
zip 174145 11879
(Note: This output shows that, before compresing, the size of the file named ff is 174145 bytes. After
compresing using bzip2, its size becomes 13976 bytes. After compresing using gzip, its size
becomes 11746 bytes. After compresing using zip, its size becomes 11879 bytes. The table shows that,
for file ff, the most eficient compresing program is gzip. Please note that the columns of the table
must be left-aligned.)
KIT501 Asignment 2
Page 2 of 6
Task B
Write a shel script. (to run on the Bourne shel) 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 los of practical significance of this litle utility, we can ignore multiple
logins from the same user during a time period of les than 3 seconds.
You would ned to research some of these UNIX comands: cut, sort, cmp.
Your script. for this task must be named log.sh. The folowing is a sample output of
the script. (It is OK that the script. leaves behind a temporary file when it is finally
interupted). The $ is the shel 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 curent time when this script. is run.)
KIT501 Asignment 2
Page 3 of 6
Task C
A telephone directory file, teledir.txt, maintains records in the form.
name:number
where number is of the form. xxxxxxxx. The folowing is an example of such
telephone directory file:
John Smith:63243333
Sally Williams:62269988
Dan Roberts:63365577
Ray Jackson:62278989
Devise a shel script. (to run on the Bourne shel) 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 leters 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 begining of your
script. you ned to verify that the telephone directory file (teledir.txt)actually
exists under the curent directory.
Your script. for this task must be named phone.sh. Here are sample outputs of your
script. The $ is the shel prompt.
$ 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
KIT501 Asignment 2
Page 4 of 6
For All Your Scripts
You must
• Include your ful name, student ID, and a brief introduction of what the
script. does in all your shel scripts, as a coment in the begining of each
script.
• Make your scripts run on the Bourne shel, regardles of which shel the user
of your scripts is curently on.
• Add in-line coments 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 wil be
marked as part of the assesment proces.
Submiting Your Asignment
You must submit a single folder named KIT501a2 which contains the folowing five
(5) files, electronically to the KIT501submit folder which has ben 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 schol'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 chose copy from the pop-up
context menu. Navigate to the KIT501submit folder (which is located in your
alacritas account [M: drive in the schol computer lab]), right-click on it, and chose
paste from the pop-up menu. You should lok in the KIT501submit folder to verify
that your assignment files are there.
IMPORTANT NOTE: The KIT501submit folder wil be created for you
automatically close to the submision time – do not create it yourself as this may
cause your assignment to not be submited corectly. If the KIT501submit folder
does not exist (or you accidently delete it), please visit the Schol Help Desk.
You must also submit a signed cover sheet to the KIT501 assignment box located at
the Schol Help Desk or Reception. Asignments without a signed covershet wil
NOT be marked.
Please note: It is your responsibility to ensure that your assignment has ben
successfuly submited to the corect folder on alacritas. If you require assistance
with this please visit the Schol Help Desk.
If your assignment is late then you should submit your files to the KIT501late
folder. The late folder wil be created automatically after the due date and wil be
available for one wek only.
KIT501 Asignment 2
Page 5 of 6
Need Help?
You are encouraged to sek assistance from your lecturer after you have seriously thought about the
assignment. Please note that we can provide general advice, however, we wil not help you write any
code, nor wil we help you debug.
(Se next page for the asignment marking scheme)
KIT501 Asignment 2
Page 6 of 6
Appendix: KIT501 Asignment 2 Marking Scheme
Script. compr.sh (for each item there are only 3 posible marks: 100% or 50% or 0%)
Item Mark
Execution of the shel script.
Script. runs as expected (2). Script. runs but not as expected (1). Script. does not run (0)
2
Include name, ID, and brief introduction in all scripts
2
Apropriate in-line coments
2
Verify that the manipulated file actually exists under the curent directory and is
readable
2
Obtain the size of the file before and after compresion 2
Corectly use bzip2, gzip, and zip to compres the file 2
Corectly 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 posible marks: 100% or 50% or 0%)
Item Mark
Execution of the shel script.
Script. runs as expected (2). Script. runs but not as expected (1). Script. does not run (0)
2
Include name, ID, and brief introduction in all scripts
2
Apropriate in-line coments
2
Corectly set up infinite lop 2
Display every 3 seconds “No user has loged in/out in the last 3 seconds.” when
this is true
2
Corectly report users who have loged in 2
Corectly report users who have loged out 2
Script. phone.sh (for each item there are only 3 posible marks: 100% or 50% or 0%)
Item Mark
Execution of the shel script.
Script. runs as expected (2). Script. runs but not as expected (1). Script. does not run (0)
2
Include name, ID, and brief introduction in all scripts
2
Apropriate in-line coments
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
Corectly display the entry when an existing valid name is suplied as an
argument
2
Corectly display the entry when an existing valid number is suplied as an
argument
2
Script. is able to handle arguments which are ful names (with double quotes) 2
Others (for each item there are only 3 posible marks: 100% or 50% or 0%)
Mark
Shel scripts structure and layout
Clear and tidy (2). Somewhat mesy but understandable (1). Mesy (0)
2
Asignment Total: /50