1 KIT501 UNIX Scripting Assignment Due Date: 3:00pm Thursday the 30th of
September – Week 11 Weight: 15% of your final KIT501 result
Introduction There are two (2) 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 ictteach) and
use kit501a2 as your working directory for this assignment. Assignment
script submissions will be marked by the KIT501 tutors on ictteach. If
you write and test your scripts elsewhere it’s your responsibility to
ensure that your scripts run correctly on the School UNIX system
(ictteach) – you must test your scripts run correctly on ictteach before
you submit. You must also submit your assignment scripts via this
server as well as a screenshot of your terminal/putty window to MyLO for
feedback purposes (see Submitting Your Assignment section). Please
pay close attention to the marking scheme shown on the last page. This
scheme shows you how marks are allocated, and what you must
(successfully) achieve to receive marks. Note also that your scripts
must have clear and tidy structure, have good use of indentation and
whitespace (to make the script readable), include appropriate comments,
and have your identification details and the script’s purpose specified
in comments at the top of your script. All scripts should be completed
using syntax and commands discussed in past (and some future) practical
classes – no additional referential syntax is needed (so your script
solutions should not use alternative constructs and syntax sourced from
e.g. google that are not taught in the unit) KIT501 ICT Systems
Administration Fundamentals 2021 Unix Scripting Assignment 2 Task A
Write a shell script (to run on the Bourne shell) that takes a filename
as argument and then compresses and decompresses the file using the
following commands in turn: Compression commands Decompression commands 1
bzip2 bunzip2 2 gzip gunzip 3 zip unzip For each of the compression
commands, the script must note the size of the file before and after
compression. Then, the script must display a simple table showing the
name of the file and: the compression command used, the file’s
uncompressed size, the file’s compressed size. Before using any
compression command to manipulate the file, your script must verify that
the filename provided as an argument to your script actually exists
under the current directory and is readable. You must also use the
matching decompression command listed in the table above to restore the
file to its uncompressed prior state in each case. Specific Task A
Requirements 1. Your script for this task must be named compr.sh. 2.
Make sure your script is user-friendly and follows common sense – your
script should use consistent indentation and include whitespace/blank
lines (where relevant) to make the script more logical and easier for a
person to read. You must also include general inline comments in the
script code to indicate the purpose of more complex command combinations
etc. 3. Your script must include comments at the start to specify: a.
the script’s purpose, b. the author (including student number), c. and
the date (when last modified). 4. One filename must be supplied as an
argument to be used by your script when it is executed by the user.
Continued on next page… KIT501 ICT Systems Administration Fundamentals
2021 Unix Scripting Assignment 3 5. Near the beginning of your script,
you need to check that the file associated with the filename provided as
an argument to the script: a. Exists under the current directory. If
the file does not exist, your script must display an error message and
then it should exit. b. Is readable. If the file is not readable, your
script must display an error message and then it should exit. 6. Your
script must generate output similar to the example shown in the next
subsection, Task A Example output. 7. Clean up – remove all temporary
files created (if any) at the end of your script and make sure the file
is in the original, decompressed state. Hints: You might like to
research some of these UNIX commands and their options: ls, cut,wc in
addition to the compression/decompression commands Task A Example output
The following is a sample output of the script. The $ is the shell
prompt and ff is an example file name for a file that exists in the
current directory: $ ./compr.sh ff File: ff bzip2 174145 13976 gzip
174145 11746 zip 174145 11879 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 the file ff, the
most efficient compressing program is gzip. Please note that the
columns of the table must be left-aligned. KIT501 ICT Systems
Administration Fundamentals 2021 Unix Scripting Assignment 4 Task B
Write a shell script (to run on the Bourne shell) that uses an infinite
loop (i.e. it runs forever unless interrupted by the control-c key
sequence) to check every 3 seconds to report on who logs into and who
logs out of a UNIX system. To simplify the script, you can ignore
multiple logins from the same user during a time period of less than 3
seconds, or cases where a user logs in and logs out during the same 3
second time period. Specific Task B Requirements 1. Your script for this
task must be named log.sh 2. Make sure your script is user-friendly and
follows common sense – your script should use consistent indentation
and include whitespace/blank lines (where relevant) to make the script
more logical and easier for a person to read. You must also include
general inline comments in the script code to indicate the purpose of
more complex command combinations etc. 3. Your script must include
comments at the start to specify: a. the script’s purpose, b. the author
(including student number), c. and the date (when last modified). 4.
When the script starts executing, it must display the following: The
current time is: followed by (on the next line) the current date and
time e.g. Wed Sep 1 13:18:32 AEST 2021 5. The script must then display a
sorted list of usernames of users who are currently logged in: (using
example usernames) The current users are: dherbert jsmithe sxu 6. Then,
every three seconds, the script must display a list of users who have
logged in, followed by a list of users who have logged out: (using
example usernames) User abcd has logged in. User jsmith has logged in.
User dherbert has logged out. User jsmithe has logged out. Continued on
next page… KIT501 ICT Systems Administration Fundamentals 2021 Unix
Scripting Assignment 5 If no user logged in or out during a three second
period, then the following message should be displayed: No user has
logged in/out in the last 3 seconds. Hints: You could research some of
these UNIX commands and their options: who, cut, sort, cmp,grep. Task B
Example output The following is a sample output of the script (It is OK
if the script leaves behind a temporary file when it is finally
interrupted). The $ is the shell prompt. $ ./log.sh The current time is:
Wed Sep 1 13:18:32 AEST 2021 The current users are: Dherbert jsmithe
sxu No user has logged in/out in the last 3 seconds. No user has logged
in/out in the last 3 seconds. User abcd has logged in. User jsmith has
logged in. No user has logged in/out in the last 3 seconds. User abcd
has logged out. User dherbert has logged out. No user has logged in/out
in the last 3 seconds. … … … … … … … … etc KIT501 ICT Systems
Administration Fundamentals 2021 Unix Scripting Assignment 6 Submitting
Your Assignment You must make two submissions – one to MyLO and one on
the teaching server, ictteach directly. The MyLO submission is purely
for attaching your assignment feedback to, whereas the ictteach
submission is your script files. MyLO submission: In order to provide
individual feedback through MyLO for this assignment, there needs to be
some submission in MyLO to attach the feedback to. You must submit a
screenshot (picture) of your terminal/putty window showing a connection
to ictteach. Note the contents of this screenshot itself will not be
assessed, so it’s not important to display any file in the output of
your terminal/putty window – a picture of the shell prompt (which will
show your username) will do. You must submit this screenshot via
Assessments → Assignments → Assignment 2 (scripting) – screenshot before
the submission cut-off time. If you do not submit this part, you may
not receive individual feedback. ictteach submission: This is the most
important submission – you must submit (copy) a single folder named
kit501a2 which contains the following two (2) files to the kit501submit
folder which was automatically created for you in your ictteach account:
compr.sh, log.sh Please ensure your kit501a2 folder only contains the
two files as listed here, when you are ready to submit your assignment.
WARNING: Do not manually create the kit501submit folder using the mkdir
command in your home directory, the folder should already be created
for you (unless you deleted it) – if you see this folder in your home
directory, DO NOT DELETE IT. Please read below for further details. To
submit your assignment, follow these steps: 1. Verify you have the
KIT501submit submission folder link (note – this is NOT a normal
directory, it is a softlink). See the section Verify the kit501submit
submission folder exists. 2. If you are missing the submission folder
link, or it is just a normal directory, create your submission folder
link. See the section Create the KIT501submit submission folder. 3.
Ensure that both your kit501a2 folder and the kit501submit folder are
present under your home directory. KIT501 ICT Systems Administration
Fundamentals 2021 Unix Scripting Assignment 7 4. Type the following
commands to copy your kit501a2 folder into your kit501submit folder (the
$ is the shell prompt): $ cd (This takes you back to your home
directory from anywhere) $ cp -r kit501a2 kit501submit (This copies your
assignment folder into your kit501submit folder. The option -r is
important) $ ls -l kit501submit (Verify that your assignment folder is
now in your kit501submit folder) $ ls -l kit501submit/kit501a2 (Verify
that your assignment files are now in your kit501submit folder) Verify
the kit501submit submission folder exists 1. Verify your kit501submit
submission folder exists with following commands ($ is the shell prompt
and username is your username) $ cd $ ls -l | grep kit501submit Other
output.. kit501submit -> /u/submissions/kit501/username 2. The
important part to note is highlighted above. The kit501submit folder is
actually a softlink to another folder elsewhere in the filesystem. The
shell is displaying this fact by including an arrow (->) and then the
ultimate location the softlink refers to. If your kit501submit folder
does not look like this (or it is missing), then you need to create the
softlink – see the next section. Create the kit501submit submission
folder Only perform this section if you are missing the kit501submit
folder softlink. 1. If you had a manually-created kit501submit folder
and you want to keep anything it contains, use the following commands to
create a backup prior to removing it ($ is the shell prompt and
username is your username): $ cd $ mv kit501submit kit501BACKUP $ rm -r
kit501submit 2. Create the kit501submit submission folder with following
command ($ is the shell prompt and username is your username) KIT501
ICT Systems Administration Fundamentals 2021 Unix Scripting Assignment 8
$ cd $ ln -s /u/submissions/kit501/username kit501submit Late
submission If your assignment is late then you should submit your
script files to the kit501late folder on ictteach (as well as a
screenshot of your terminal/putty window to MyLO). This kit501late
folder will be created immediately after the assignment due date and it
will be available for one week only. Do not create this folder yourself,
it will be created automatically. After submitting late by following
the steps below, make sure not to touch your late submission files in
the kit501late folder as this will change the recorded timestamps. The
submitted files will be copied after 24 hours late and 1 week late. $ cd
(This takes you back to your home directory from anywhere) $ cp -r
kit501a2 kit501late (This copies your assignment folder into your
kit501late folder. The option -r is important) $ ls -l kit501late
(Verify that your assignment folder is now in your kit501late folder) $
ls -l kit501late/kit501a2 (Verify that your assignment files are now in
your kit501latet folder) Need Help You are encouraged to seek
assistance from your lecturer or tutor after you have seriously thought
about the assignment. Please note that we can provide general advice –
but you are expected to write and debug (correct) your own code. When
writing your script, think about what steps you need to do, don’t try to
write the code all at once. Implement a small part first, test that it
is working correctly, then implement a bit more, repeating the process
of thinking, writing (coding), testing and refining/fixing. If you are
still stuck, some suggested hints are given below, but your solution may
be implemented differently – that’s ok! Task A Extra Hints: Start by
determining the provided filename from the script’s argument parameters
Verify the file exists – exit if it doesn’t Verify the file is
readable – exit if it isn’t KIT501 ICT Systems Administration
Fundamentals 2021 Unix Scripting Assignment 9 Work out how to
determine the file’s size – there are several ways to do this, and you
then need to only capture (remember) a certain portion of the output
from the command(s) you chose to achieve this (specifically where the
file’s size is reported) Work out (test) how the compression commands
work, and what sort of output they create Compress the file and work
out how to then determine the file’s new size (like before) Display a
row of the table output that contains the compression command used and
the before and after file sizes Decompress the file (using the
appropriate command) and repeat the process for the other compression
commands Task B Extra Hints: Work out how to determine who is logged
in – you only want the username part of the output Remember the list
of users you’ve found above to a file (imagine this is the first list)
Create a loop that will run every 3 seconds Within the loop,
determine again who is logged in (saving the username results to another
file – imagine this is the second list). Compare this list of usernames
with the first list you saved before. Differences between the files
indicate usernames who have logged in or out – for each file you may
have to use another loop to go through each username in turn in order to
determine if it’s present (or not) in the other file. For example, if a
user “bob” is in the first list of usernames but not the second list of
usernames, then bob has logged out. If bob is in the second list but
not the first list, then bob has logged in. If both lists are exactly
the same, then no-one has logged in or out. Each iteration of your
loop, the second list of usernames from before should become the first
list of usernames (they are now old, from 3 seconds in the past) so you
can then compare it with a (new) second list of usernames that have just
been found. Some users might be logged in multiple times at once, so
when you generate a list of who’s logged in, your list should be sorted
and only contain unique usernames… Plagiarism Plagiarism is a very
serious matter, and ignorance of this is not an excuse. If you submit
work claiming it to be your own, and it is not original work of your
own, this is cheating. This means for example that you cannot submit
large sections of code written by other students or sourced from the
Internet and claim you wrote the code yourself. Plagiarism can result in
academic penalties both in relation to your assignment, and also on
your permanent university record. Acknowledgements: This assignment has
been re-formatted and modified from an assignment written by Dr Shuxiang
Xu. KIT501 ICT Systems Administration Fundamentals 2021 Unix Scripting
Assignment 10 KIT501 Assignment 2 Marking Scheme Task A – compr.sh Out
of Overall execution of the shell script Script runs as expected (2) 2
Script Comments Appropriate comments (in-line and at start of script)
(2) 2 Script Layout Appropriate layout, including indentation and
whitespace (2) 2 File Verification Filename is provided by a script
parameter (argument) (1) File specified by the filename argument is
verified to exist and be readable, exiting otherwise (2) 3 File size
determination Correctly determine the size of the file before and after
compression (4) 4 Compression Correctly use bzip2, gzip, and zip to
compress the file (2) 2 Output Correctly display an output table which
shows the specified information (2) The columns of the table are
left-aligned as required (2) 4 Cleanup Remove any temporary files and
ensure file is in the original decompressed state (1) 1 Total 20 Task B –
log.sh Out of Overall execution of the shell script Script runs as
expected (2) 2 Script Comments Appropriate comments (in-line and at
start of script) (2) 2 Script Layout Appropriate layout, including
indentation and whitespace (2) 2 Initial Output Display the message “The
current time is:” followed by the current time (2) Display a sorted
list of usernames of users who are currently logged in at the start (2) 4
Continuing Output Repeat output correctly every 3 seconds (2) Correctly
report users who have logged in since the last report (3) Correctly
report users who have logged out since the last report (3) Correctly
display “No user has logged in/out in the last 3 seconds.” (2) 10 Total
20 Assignment Total: 40