KIT213 UNIX Scripting Assignment Due Date: 3PM Wednesday Week 13, 12 October 2022
Weight: 30% of your final KIT213 result 1. Introduction
This assignment requires you to apply what you have learned from the unit’s practical classes to write a script to implement task specified below. You must complete this assignment individually and pay careful attention to the section on plagiarism to ensure the work you submit is your own.
2. Workingenvironment
Copyright By PowCoder代写 加微信 powcoder
On the teaching server, ictteach.its.utas.edu.au, you must make a directory named kit213script 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 kit213script
$ cd kit213script
2. Every other time you log on, simply do the following and then continue working:
$ cd kit213script
3. 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).
Your solution is restricted (i.e not allowed) to use the shell “builtin” binary conversion syntax e.g. echo $((2#101010101))
KIT213 Operating Systems 2022 Scripting Assignment
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 , bc
The unit also has not discussed arrays, so syntax similar in form to powers=(128 64 32 16 8 4 2 1) #an array
for i in do
something ${powers[$i]} done
is strictly prohibited.
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). If in doubt as to what syntax or commands may be used, ask your tutor or the lecturer.
4. AssessmentProcess
All student script submissions will be marked 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.
➢ Pay close attention to the marking rubric 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 more readable by humans), include appropriate comments, and have your identification details and the script’s purpose specified in comments at the top of your script.
5. ScriptingTaskOverview
5.1 Scenario
There is a long tradition of producing line-based character art for a terminal using the limited character representation available in the ASCII character set. In this assessment task, you are working for a fictional company that wants to create some simple command-line “banners” that include letters, numbers and possibly patterns from pre-defined binary data that will need to be converted from decimal format. The pre-defined decimal-format data for the alphabet and numerals has been created by the company’s art department.
KIT213 Operating Systems 2022 Scripting Assignment
Each individual pattern that will ultimately be shown in the terminal window will be based on 8 rows of binary data (an 8 by 8 grid of “pixels”). As an example, consider a representation of the letter ‘A’:
Column value
128 64 32 16 8 4 2 1 27 26 25 24 23 22 21 20
Each column in the diagram above represents a power of two, and each entire row represents an 8- bit value (a byte), so the whole letter ‘A’ above uses 8 bytes for this representation. If a pixel (a particular row and column location) is white, that is the equivalent of a zero in the column for that row. If a pixel is black, it is the equivalent of a 1. In pure binary, the whole letter above is represented by the following binary patterns:
The value for the top row here is 0 in decimal. The next row has a 1 in the 25 column (32), a 1 in the 24 column (16), and a 1 in the 23 (8) column. This makes the second row (byte) value 32+16+8 = 56, the row value for the third row 64+32+8+4 = 108 etc.
5.2 Provided source “artwork” files
The entire uppercase alphabetic characters and the numeric characters 0-9 have been pre-drawn by the art department in a similar manner to that describe above. However, the data for these characters has unfortunately been generated as a series of individual files (with 8 files per character/pattern) that contain no data – instead, the encoded data binary value is part of each file’s name as a decimal number.
Continuing with the letter ‘A’ example as well as the representation for the letters ‘B’ and ‘C’ (shown below), they are represented in the provided source files using the following filenames:
KIT213 Operating Systems 2022
Scripting Assignment
Letter ‘A’
Letter ‘B’
Letter ‘C’
AA2-56.grf
AA3-108.grf
AA4-198.grf
AA5-198.grf
AA6-254.grf
AA7-198.grf
AA8-198.grf
AB2-252.grf
AB3-198.grf
AB4-198.grf
AB5-252.grf
AB6-198.grf
AB7-198.grf
AB8-252.grf
AC2-60.grf
AC3-102.grf
AC4-192.grf
AC5-192.grf
AC6-192.grf
AC7-102.grf
AC8-60.grf
128 64 32 16 8 4 2 1 Row 27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1 Row 27 26 25 24 23 22 21 20
5.3 Source artwork original naming convention
The format of each provided source filename is the following, which is only important if you manually copy any of the files to your own local directory:
First character
Second character
Third character
Fourth character
Fifth (and possibly sixth and seventh) characters
Last 4 characters
A literal ‘A’
The letter being represented (i.e. ‘A’ , ‘B’ , ‘C’ … ‘Z’, ‘0’ .. ‘9’)
The row number from each 8×8 grid, starting from 1
A dash (-)
The decimal value of the original byte for each row in the character’s representation grid – this ranges from 0 .. 255
A file extension – the source files use .grf
All provided source art files can be found in the following directory:
/units/kit213/assignment
Try to list the contents of that directory (with one filename per line using the -1 (minus one) option, (the $ is the prompt)):
$ ls -1 /units/kit213/assignment
KIT213 Operating Systems 2022 Scripting Assignment
You will see in the output that the files are listed in a particular order – this is the reason for the filename convention used, as ls will list the files in alphabetic and numeric order, preserving the grouping of 8 files per represented character. There are some extra “symbols” that are also included at the end that you can also use/test with if you want to – these include:
• The space character (ZA…)
• A black solid square (ZB…)
• A square shape (ZC…)
• A triangle shape (ZD…)
5.4 Copying source artwork
• A checkerboard (ZE…)
• A diamond shape (ZF…)
• Diagonal left lines (ZG…) • Diagonal right lines (ZH…)
Part of your assignment task will require you to initially copy some of the source artwork files to your own local directory for processing by the script you will be creating later, however, to simplify and aid with this copying, a command-line program is provided, called copyBinaryArt. This program will copy all of the 8 source files associated with a particular character (letter or number) or groups of letters and numbers, but during the copying will replace the first 3 letters of the source filenames with an incrementing 3-digit sequence number. This sequence number will preserve the order of the filenames when they are processed and displayed in the terminal window by your script.
copyBinaryArt can be run via the following (which will show how it is used): $ /units/kit213/assignment/copyBinaryArt
Usage: copyBinaryArt art-source art-destination starting-sequence-number string
art-source: the source directory containing the original decimal-named files
art-destination: the destination directory to copy the decimal-named files to starting-sequence-number: starting number used for first file created, incremented for each file string: the string to be converted to 8-bit decimal-named files
For example, to copy the source art files to represent the text “Hi”, the command would be: (assuming you have created a subdirectory in your current directory called “myDir”)
$ /units/kit213/assignment/copyBinaryArt /units/kit213/assignment myDir 1 “HI”
Source directory /units/kit213/assignment verified to exist! Destination directory myDir verified to exist!
The starting sequence number is 1
The string to convert is: HI
Copying files for the character ‘H’: Copying files for the character ‘I’:
After the copy has completed, the contents of MyDir would be:
002-198.grf
003-198.grf
004-198.grf
005-254.grf
006-198.grf
007-198.grf
008-198.grf
Files that represent the letter “H”
KIT213 Operating Systems 2022 Scripting Assignment
010-252.grf
011-48.grf
012-48.grf
013-48.grf
014-48.grf
015-48.grf
016-252.grf
Files that represent the letter “I”
The ultimate task for your script to complete then is to process all of the files that are contained in your local directory, converting the decimal part of each filename to binary, replacing zeros in the resulting binary values with spaces, and replacing ones with some prominent character (like an X) before displaying the result on the terminal screen. Bear in mind when your script is assessed, the marker will use completely different source files to test your script.
5.4 Source filename validity
Because of poor quality control from the art department, occasionally some files may be present in the local source directory that is used for processing (and thus testing by the marker) that do not correctly conform to the file-naming scheme. Your script will have to correctly process these files and correctly categorise (and move) them to another directory. If you have copied some valid source files to your local directory, then you will also need to manually create some invalidly named files to test your script correctly.
5.4.1 Valid filenames
Filename format: XYX-decimal.ext
➢ You are free to create your own additional artwork (using 8 filenames to represent an individual 8 by 8 grid), but your script (see below) must be able to process any validly named file that includes the naming convention described above i.e. 3-digit sequence number, dash, decimal value (0 up to 255), then a file extension (e.g. .grf).
Example: directory
any of the following would be considered potentially valid filenames in your local source (the validity will also depend on which particular filename extension has been specified)
• decimal • .ext
: a 3-digit sequence code
: the dash character
: a numeric value between 0 and 255 inclusive :a file extension such as .grf or .doc, .xls etc
001-65.grf 369-0.txt 501-127.doc 999-255.xls
5.4.2 Invalid filenames
Anything not fitting the patterns described above is invalid. Your script will need to categorise each invalid source filename as detailed below (in order of priority), and then copy the invalid source file to a specific subdirectory of your destination directory (see Task Requirements later).
KIT213 Operating Systems 2022 Scripting Assignment
• INVALID1 – one or more non-numeric characters where the decimal value should be.
• INVALID2 – numeric-only decimal values, but the decimal value is more than 255.
• INVALID3 – one or more non-numeric characters where the sequence code should be.
• INVALID4 – numeric-only sequence codes, but there are more than three digits.
• INVALID5 – numeric-only sequence codes, but there are less than three digits.
• INVALID6 – no sequence code or no decimal part.
• INVALID7 – no file extension, or the extension is different to the argument to the script.
Examples of filenames for each category:
Example invalid filenames (assume extension specified is .grf)
INVALID1 INVALID2 INVALID3 INVALID4 INVALID5 INVALID6 INVALID7
001-ba0.grf 123-256.grf a-000.grf 1222-122.grf 12-122.grf wrong.grf badfile
001-bad.grf 999-999.grf 01x-111.grf 11999-100.grf 1-100.grf -123.grf 123-100.txt1
123-12*.grf 111-1234.grf 1q7-127.grf 99999-254.grf 99-254.grf 123-.grf 911-000.doc1
6. Task Requirements (this is what your script must do)
1. Your script for this task must be named displayBanner.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:
(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).
1 File extension doesn’t match the one specified as a command-line argument! 7
KIT213 Operating Systems 2022 Scripting Assignment
5. Your script must accept 3 command-line arguments provided when the script is run:
• Argument 1 – the local source directory containing the files to be processed
• Argument 2 – the local destination directory that will be used to copy invalid
filenames to
• Argument 3 – the file extension (without a leading dot) to be used for valid source
files (eg grf)
The directory names and the file extension that are provided by arguments 1,2 and 3 must not be ‘hardcoded’ (specified literally) in your script, i.e., their value must come from the command line arguments. If any of the 3 arguments are missing, the script should provide a usage warning message and then exit – the user must not be prompted to enter missing values when the script is running. See Example Output.
6. Near the beginning of your script, you need to check for each of the directories associated with the arguments 1 and 2 (the source directory and the destination directory):
a. Exists. If the directory does not exist, your script must display an error message and then it should exit. The directory name provided must use a relative path – see Example Output for examples.
b. Is readable, executable (for both directories) and writeable (for the destination).
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 source directory, the script must:
a. For a validly named file:
i. Extract the decimal value from the filename, convert it to 8-bit binary, and then output to the terminal window the binary value but with every 0 replaced with a space character (” “) and every 1 replaced with an “X” character. The following is an example of the decimal value 59 (001110112) displayed with the space character shown below as a gray block █ for clarity purposes only):
b. For an invalidly named file that does not match the validity test:
i. display the following output to the terminal screen after all valid files have
been processed (i.e defer the output to the end of processing):
• X refers to the specific invalid category (see section 5.4.2)
KIT213 Operating Systems 2022
Scripting Assignment
filename refers to the original source filename invalid-description refers to the text defined at the end of this step)
INVALIDX – filename (invalid-description)
invalid-description
INVALID1 INVALID2 INVALID3 INVALID4 INVALID5 INVALID6 INVALID7
non-numeric decimal part
decimal part too large
invalid sequence code – non-numeric characters invalid sequence code – too many digits invalid sequence code – too few digits
no sequence code or decimal part
filename wrong or missing/wrong file extension
ii. Move the invalid file to a subdirectory of the local destination directory that was specified as the second argument to the script, and call the subdirectory INVALIDX (the script should only create the subdirectory if it does not already exist and also only when a file in this category is found).
8. If the source directory specified as the first argument to the script contains no files: a. display the following output to the terminal screen:
• sourcedir refers to the directory name specified in argument 1 The directory sourcedir contained no files…
b. exit the script
9. If the source directory specified as the first argument to the script contained files:
a. display the following output to the terminal screen as the very last line of output:
• filecount refers to the number of files processed by the script filecount files were processed
b. exit the script
➢ You must also provide (submit) some specific output from testing your script on a specific sequence of test files – more details are given in the next section.
KIT213 Operating Systems 2022 Scripting Assignment
7. Test output for submission
Once your script is ready for submission, you must also include some specific test output. The easiest way to do this is to make a typescript (log) of the terminal window output. When ready, create a subdirectory for some specific art files – eg submitSource
7.1 Create a new typescript:
Script started, file is typescript
7.2 Copy artwork files
Copy the art files for your student number and first and last names to the submitSource directory, for example, if your student number is 123456 and your name is , you would use:
$ /units/kit213/assignment/copyBinaryArt /units/kit213/assignment submitSource 100 “123456 ”
Source directory /units/kit213/assignment verified to exist! Destination directory submitSou
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com