+1-415-670-9189
info@expertsmind.com
KIT213 Operating Systems Assignment Problem
Course:- Operating System
Reference No.:- EM132384329




Assignment Help
Expertsmind Rated 4.9 / 5 based on 47215 reviews.
Review Site
Assignment Help >> Operating System

KIT213 Operating Systems Semester 2, 2019
University of Tasmania
Assignment Two - UNIX Shell Programming

This is an individual assignment. There are three (3) shell programming tasks in this assignment. You are required to make a directory named kit213a2 under your home directory (on alacritas) and use kit213a2 as your working directory for this assignment.

Task A

Write a shell script (to run on the Bourne shell) that can be used to remove some old C programs you no longer wish to keep. When the script is run with no arguments supplied, it picks up each C program from the current directory and lists the first 10 lines (hint: research the head command). It then prompts for deletion of the file (the user can then choose to delete or not to delete the file). When the user supplies arguments (C program file names) with the script, it works on those files only.

Your script for this task must be named delC.sh. In designing your script you should consider the following scenarios:

• There is no C program file stored under the current directory;
• There is at least one C program file stored under the current directory;
• The user-supplied arguments list contains names of existing C programs stored under the current directory. We can assume that all the C programs have been correctly named as *.c, and that there is no special character (such as space) in any of these filenames;
• The user-supplied arguments list contains both existing and missing names of C programs stored under the current directory. Missing names refer to the files which no longer exist under the current directory.

Make sure your script is user-friendly and follows common sense (for example, when there is no C program stored under the current directory your script should display a message and then exit). The following is a sample output of the script. The $ is the shell prompt.

$ ./delC.sh
This script removes C files which you no longer want to keep. Here are the C file(s) under the current directory:
No C files found.

$ ./delC.sh
This script removes C files which you no longer want to keep. Here are the C file(s) under the current directory:
f1.c f2.c

Displaying first 10 lines of f1.c:

/* A C program for handling arrays Written by John Jones, July 2009 Updated April 2010
*/
#include <stdio.h> int main()
{
int x;

Delete file f1.c? (y/n):n (user input)
File f1.c NOT deleted.

Displaying first 10 lines of f2.c:

/* Another C program for handling arrays Written by John Jones, August 2009 Updated May 2010
*/
#include <stdio.h> int main()
{
int x, y, z;

Delete file f2.c? (y/n): y (user input)
File f2.c deleted.

$ ./delC.sh f1.c
This script removes C files which you no longer want to keep. The file(s) you want to delete is/are:
f1.c

Displaying first 10 lines of f1.c:

/* A C program for handling arrays Written by John Jones, July 2009 Updated April 2010
*/

Task B

Write a shell script (to run on the Bourne shell) that runs an infinite loop to monitor the creation and removal of .pdf or .PDF files under the current directory. Every 3 seconds it should display a list of those filenames created or removed after the previous display. Without loss of practical significance of this utility, we can assume that the time interval between creation of a .PDF or .pdf file and removal of a .PDF or .pdf file is over 3 seconds, which means that it's unnecessary for your script to handle the situation where creation of a file is followed by immediate removal of a file. (Hint: research the cmp and comm commands.)

Your script for this task must be named pdf.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 interrupted). The $ is the shell prompt.

$ ./pdf.sh

No pdf files have been created or removed in the last 3 seconds. No pdf files have been created or removed in the last 3 seconds.
The following pdf file(s) have been created in the last 3 seconds: a3.pdf
a4.pdf a5.pdf

The following pdf file(s) have been removed in the last 3 seconds: a4.pdf
a5.pdf

No pdf files have been created or removed in the last 3 seconds. No pdf files have been created or removed in the last 3 seconds.
... ... ... ... ...

Task C
Write a shell script (to run on the Bourne shell) that allows a user to view, add, or delete a setting in a configuration file (config.txt) that contains settings in the form variable=value. The following is an example of such configuration file:

HOME=/u/soc/abc
HOST=lawson
HOSTTYPE=sun4
LOGNAME=abc
OSTYPE=solaris
PATH=/usr/dt/bin:/usr/openwin/bin:/bin:.
PS1=$
PS2=> SHELL=/usr/bin/tcsh
TZ=Australia/Tasmania
USER=abc
VENDOR=sun
EDITOR=joe

Your script for this task must be named setting.sh. For ease of use, your script must present a menu of operations that a user may choose from. After the user makes a selection and that the selected operation has been completed, the menu must be displayed again so that the user can make another selection. Validation check on user inputs is required (see the following sample output about this). In the beginning of your script you need to check to see whether the required configuration file (config.txt) actually exists under the current directory (if not, your script displays a message and then exits).

Here is a sample output of your script. The $ is the shell prompt. The items in italics are not part of the sample output. They are hints indicating how your
script should behave.

$ ./setting.sh

*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - Quit

CHOICE: 1 (user input)
Enter setting (format: ABCD=abcd): (user simply presses the Enter/Return key)
New setting not entered

Enter setting (format: ABCD=abcd): EDITOR (user input)
Invalid setting (A valid setting needs to contain a "=" sign)

Enter setting (format: ABCD=abcd): EDITOR= (user input)
The variable name of the setting is: EDITOR The variable value of the setting is: Invalid setting.

(Hint: To retrieve a variable name before the "=" sign, research the expr command's ability in handling strings)

Enter setting (format: ABCD=abcd): =vi (user input)
The variable name of the setting is: The variable value of the setting is: vi Invalid setting.

Enter setting (format: ABCD=abcd): 1EDITOR=vi (user input)
The variable name of the setting is: 1EDITOR The variable value of the setting is: vi
Invalid setting. The first character of a variable name cannot be a digit.

Enter setting (format: ABCD=abcd): EDITOR=vi (user input)
The variable name of the setting is: EDITOR The variable value of the setting is: vi

New setting added.

*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - Quit
CHOICE: 1 (user input)

Enter setting (format: ABCD=abcd): USER=jchen (user input)
The variable name of the setting is: USER The variable value of the setting is: jchen
Variable exists. Changing the values of existing variables is not allowed.

*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - Quit
CHOICE: 2 (user input)

Enter variable name: EDTOR (user input)
Variable does not exist. (Your script needs to check whether a variable exists or not)

*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - Quit
CHOICE: 2 (user input)

Enter variable name: EDITOR (user input)
EDITOR=vi
Delete this setting (y/n)? y (user input)
Setting deleted (However, if user's answer is n here, then the setting stays)

*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - Quit
CHOICE: 3

Enter variable name:USER1 (user input)
Variable does not exist. (Your script needs to check whether a variable exists or not)

*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - Quit
CHOICE: 3 (user input)

Enter variable name: USER (user input)
USER=abc
Requested setting displayed above.

*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - Quit
CHOICE: 4 (user input)

HOME=/u/soc/abc HOST=lawson HOSTTYPE=sun4 LOGNAME=abc
OSTYPE=solaris PATH=/usr/dt/bin:/usr/openwin/bin:/bin:. PS1=$
PS2=>
SHELL=/usr/bin/tcsh TZ=Australia/Tasmania USER=abc
VENDOR=sun

*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - Quit
CHOICE: 5 (user input)
Invalid choice.

*** MENU ***
1. Add a Setting
2. Delete a Setting
3. View a Setting
4. View All Settings Q - quit
CHOICE: q (user input)
(The running script is terminated. The shell prompt is displayed)

Attachment:- UNIX Shell Programming.rar




Put your comment
 
Minimize


Ask Question & Get Answers from Experts
Browse some more (Operating System) Materials
I open my computer and create a new folders named Apex Carton, Manufacturing, Material Suppliers, East Coast and West Coast. Then move the East Coast and West Coast folders
What are the three different categories of command, support your answer by giving three examples. Give three good reasons, with valid explanation, to justify why partitioni
Create a use-case diagram to include at least three (3) actors for the system described in this case through the use of graphical tools in Microsoft Word or Visio, or an ope
Visually associates the hardware components described in your text in Computer Hardware Review, Section 1.3 (CPU, Memory and Disks) with its associated operating system abst
Your corporation has just occupied an old historic building in which fifteen workers will work. Due to historic building codes, the corporation is not permitted to run cables
Given multi-network access, it's not unusual for users to have multiple user identifications and passwords. How would you manage these multi-password situations? Describe both
Proper design and implementation of the ETL process is crucial to a BI project. ETL is considered the most time consuming phase of the Data Warehousing project. Therefore, any
The Internet can be used for several reasons, including research and education, and information can be  achieved  from many types of Web sites.