Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Microsoft Word - KIT501_A2_2018.docx KIT501 Assignment 2 Page 1 of 6 KIT501 ICT Systems Administration Fundamentals Semester 2, 2018 Assignment Two – UNIX Shell Programming (10% of your KIT501 final...

1 answer below »
Microsoft Word - KIT501_A2_2018.docx
KIT501 Assignment 2
Page 1 of 6
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 co
ectly 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:

zip2 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 cu
ent 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):

$ compr.sh ff
File: ff
zip XXXXXXXXXX
gzip XXXXXXXXXX
zip XXXXXXXXXX
(Note: This output shows that, before compressing, the size of the file named ff is XXXXXXXXXXbytes. After
compressing using bzip2, its size becomes 13976 bytes. After compressing using gzip, its size
ecomes 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.)
KIT501 Assignment 2
Page 2 of 6
Task B

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
inte
upted). The $ is the shell prompt.

$ log.sh
The cu
ent time is:
Tue August 24 12:18:28 EST 2018

The cu
ent users are:
abc
v0
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 cu
ent time when this script is run.)


KIT501 Assignment 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 following is an example of such
telephone directory file:

John Smith: XXXXXXXXXX
Sally Williams: XXXXXXXXXX
Dan Roberts: XXXXXXXXXX
Ray Jackson: XXXXXXXXXX

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 cu
ent directory.

Your script for this task must be named phone.sh. Here are sample outputs of your
script. The $ is the shell prompt.

$ phone.sh john
John Smith: XXXXXXXXXX

$ phone.sh Smith
John Smith: XXXXXXXXXX

$ phone.sh “John Smith”
John Smith: XXXXXXXXXX

$ phone.sh XXXXXXXXXX
Sally Williams: XXXXXXXXXX

$ phone.sh Adams
Name does not exist

$ phone.sh XXXXXXXXXX
Number does not exist

$ phone.sh XXXXXXXXXX
Invalid phone number

$ phone.sh XXXXXXXXXX
Invalid phone number

$ phone.sh Smith1
Invalid name
KIT501 Assignment 2
Page 4 of 6
For All Your Scripts
You must
• Include your full name, student ID, and a
ief 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 cu
ently on.
• Add in-line comments to help other people understand your scripts.
• Use “\n” where appropriate to make the output of your scripts more
eadable.
• 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 co
ectly. 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 co
ect 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 5 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 6 of 6
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
Script runs as expected (2). Script runs but not as expected (1). Script does not run (0)
2
Include name, ID, and
ief introduction in all scripts 2
Appropriate in-line comments 2
Verify that the manipulated file actually exists under the cu
ent directory and is
eadable
2
Obtain the size of the file before and after compression 2
Co
ectly use bzip2, gzip, and zip to compress the file 2
Co
ectly 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
Script runs as expected (2). Script runs but not as expected (1). Script does not run (0)
2
Include name, ID, and
ief introduction in all scripts 2
Appropriate in-line comments 2
Co
ectly 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
Co
ectly report users who have logged in 2
Co
ectly 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
Script runs as expected (2). Script runs but not as expected (1). Script does not run (0)
2
Include name, ID, and
ief introduction in all scripts 2
Appropriate in-line comments 2
Answered Same Day Sep 27, 2020 KIT 501

Solution

Meenakshi answered on Oct 04 2020
164 Votes
echo "enter the filename for zip and unzip"
ead fname
zip2 filename
gzip filename
zip -r filename.zip filesdir
unzip2 filename.bz2
gunzip filename.gz
unzip filename.zip
du -hs * |awk '{print $2 "\t" $1}'
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here