Reference no: EM133139685
KIT501 UNIX Scripting - University of Tasmania
Learning Outcome 1: Apply industry standard techniques and skills to configure network infrastructure and operating system processes.
Working environment
On the teaching server, ictteach.its.utas.edu.au, you must make a directory named kit501script in your home directory and use this directory as your working directory for all assignment development.
1. The first time you start working on the assignment, after logging on, type the following commands ($ is the prompt, do not type that):
$ mkdir kit501script
$ cd kit501script
2. Every other time you log on, simply do the following and then continue working:
$ cd kit501script
Allowed Syntax/Commands
All scripts must be completed using syntax and commands discussed in past (and some future) practical classes - no additional referential syntax (that is not discussed in practicals) is allowed. This means your script solutions must not use alternative constructs and syntax e.g. solutions found through websites via google searches that use commands and shell syntax that we have not covered in the practical content, and you must not use external parties or other individuals to write the scripts for you (this is considered plagiarism and academic misconduct).
1 Assessment Process
All student script submissions will be marked by KIT501 tutors on ictteach according to the rubric on the last page of this document. If your scripts were developed elsewhere (i.e., not on ictteach) it's your responsibility to ensure that your scripts run correctly in our teaching environment. You will lose considerable marks if your scripts do not run correctly on our teaching server, so it is imperative you develop and test your scripts on ictteach before you submit.
Scripting Task
Overview
A researcher has used a logging program to log observations for an experiment. The output of the logging program is a series of log files in a directory that have the following naming format:
fileABCDEFGH
where file is literally the word 'file', and A..H are single binary digits (0 or 1).
The researcher did not realise for several weeks that the logging program's output filenames had binary digits, and, unfortunately, her further research work requires the filenames to be fixed to replace the binary part with the decimal number. The researcher also mistakenly added other files to the directory containing the log files, and these other files do not have the correct naming format. She wants you to write a script to rename the validly-named files, and then sort all the files in her directory into one of four subdirectories depending on their filename - the script must also output what files (and their associated 'category') are found.
Valid filenames
Any of the following would be considered potentially valid filenames produced by the researcher's logging program (all categorised as CATEGORY1) - a filename that starts with file followed by 8 binary digits:
• file00000000
• file00000001
• file00000010
• ...
• file11111111
Invalid filenames
Anything not fitting the pattern described above is invalid.
• CATEGORY2 - filenames that start with file that are followed by zero or more binary digits only (but less than 8 binary digits) e.g. file, file0101, file0000000
• CATEGORY3 - filenames that start with file that are followed by any characters that include non-binary digits e.g. filesort0101, file00112110, fileWRONG
• CATEGORY4 - any filename that does not start with file e.g. badfile, fire01001010
The researcher's request means your script must require an arbitrary directory name to be specified when it is run, after which it will then rename any valid filenames and move the files it finds in the specified directory according to the requirements that follow:
Task Requirements
1. Your script for this task must be named binarylog.sh
If your script has a different name, it will not be assessed.
2. Make sure your script is not unnecessarily complex - 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 start with the following first line:
#!/bin/sh
(this specifies the shell to be used to interpret the rest of the commands in the script)
4. Your script must include comments at the beginning (near the top of the script) to specify:
a. the script's purpose,
b. the author (including student number),
c. and the date (when last modified).
5. One directory name must be supplied as an argument to be used by your script when it is executed by the user (the directory referred to would presumably be one that contains a mixture of validly named and invalidly named log files that are going to be processed by the script). The directory name must not be 'hardcoded' (written) in your script, i.e., its value must come from the command line argument. If no directory name is provided by the user, the script should provide a usage warning message and then exit. See Example Output for an example.
6. Near the beginning of your script, you need to check that the directory associated with the directory name provided as an argument to the script:
a. Exists. If the directory does not exist, your script must display an error message and then it should exit. The directory name provided can use an absolute path, or a relative path - see Example Output for examples.
b. Is readable, writeable and executable.
i. If the directory is not readable, your script must display an error message and then it should exit.
ii. If the directory is not writeable, your script must display an error message and then it should exit.
iii. If the directory is not executable, your script must display an error message and then it should exit.
7. For every file in the specified directory, the script must:
a. For a validly named file:
i. echo the following output to the terminal screen:
ii. Rename the file with its specific filedecimal name and then move it to a
subdirectory called CATEGORY1 (the script should only create the directory here if it does not already exist and also only when a file in this category is found). See the section Binary to Decimal Renaming below.
b. For an invalidly named file that starts with file and is then followed by less than 8 binary digits (and no other characters):
i. echo the following output to the terminal screen:
ii. Move the invalid file to a subdirectory called CATEGORY2 (the script should
only create the directory here if it does not already exist and also only when a file in this category is found).
c. For an invalidly named file that starts with file and is followed by any characters that include some non-binary digits:
i. echo the following output to the terminal screen:
ii. Move the invalid file to a subdirectory called CATEGORY3 (the script should
only create the directory here if it does not already exist and also only when a file in this category is found).
d. For an invalidly named file that does not start with file:
i. echo the following output to the terminal screen:
ii. Move the invalid file to a subdirectory called CATEGORY4 (the script should only create the directory here if it does not already exist and also only when a file in this category is found).
8. If the command-line argument specified directory contains no files:
a. echo the following output to the terminal screen:
b. exit the script
This also means if you run the script twice, the first time should process any files, displaying the outputs specified in requirement 7 above, renaming where appropriate, and moving files to specified category subdirectories. Running the script for a second time (with the same directory argument) will produce the output specified in this requirement (requirement 8), as all files should have already moved to subdirectories. Your output should never "process" or mention the subdirectory names.
Binary to Decimal Renaming
As previously mentioned, a validly named file will have the form fileABCDEFGH, eg file01010111
Your script must implement an algorithm only using commands and syntax as discussed in practical classes. Your solution is restricted (i.e not allowed) to use the shell "builtin" conversion
e.g. echo $((2#101010101))
This restriction also extends to any other command that has not been discussed in classes - the following list shows some of the common methods (but not all) found through a brief google search - none are permitted:
awk sed printf xxd od perl ibase, obase and bc
Instead, your solution must take an iterative (looping) approach to demonstrate your understanding of iteration and selecting individual characters from a string (a string is just a sequence of characters).
Attachment:- UNIX Scripting.rar
Attachment:- ICT Teaching Server ictteach.rar