There are three (3) shell programming tasks in this assignment. This is an individual assignment. You are required to make a directory named kit104a2 under your home directory (on alacritas), and use kit104a2 as your working directory for this assignment.
Assignment submissions will be marked by the KIT104 tutors on alacritas. If you write and test your scripts elsewhere its your responsibility to ensure that your scripts run correctly on the School UNIX system (alacritas).
Task A
Write a shell script (to run on the Bourne shell) to copy all the files from the directories named dir1 and dir2 into a new directory named dir3.
(1). In the beginning of your script you need to check that the directories dir1 and dir2 exist under the current directory (if not, your script displays an error message and then exits).
(2). All the three directory names are supplied as arguments, and the new directory dir3 must not currently exist (ie, the creation of dir3 is part of the script).
(3). The script first copies all the files from dir1 into dir3.
(4). The script then copies every file from dir2 to dir3 subject to these conditions: if the file from dir2 is not already present in dir3, or if the dir2 file is newer than the same dir3 file it will overwrite its namesake in dir3.
(5). Remove all the temporary files (if any) at the end of your script.
(6). Your script must generate an output similar to the sample output shown in the top box of page 2.
Hint: You should note that the cp command without any option does not preserve certain attributes (such as ownership and timestamps).
Your script for this task must be named cp2.sh. Make sure that your script is user-friendly and follows common sense. The following is a sample output of the script. The $ is the shell prompt.
| $ ./cp2.sh dir1 dir2 dir3 These files from dir1 copied into dir3:a.c b.c file1.c These new file(s) from dir2 copied into dir3: file2.cThese file(s) from dir2 copied into dir3 and overwrite(s) their namesakes in dir3: a.c |
The following sample outputs verify the above result:
| $ ls cp2.sh dir1 dir2 dir3 $ ls -l dir1 total 12-rw-rr 1 sxu staff 9 Aug 2 12:52 a.c-rw-rr 1 sxu staff 9 Aug 2 12:52 b.c-rw-rr 1 sxu staff 9 Aug 2 12:52 file1.c $ ls -l dir2 total 12-rw-rr 1 sxu staff 9 Aug 2 12:53 a.c-rw-rr 1 sxu staff 9 Aug 2 12:51 b.c-rw-rr 1 sxu staff 9 Aug 2 12:53 file2.c $ ls -l dir3 total 16-rw-rr 1 sxu staff 9 Aug 2 12:53 a.c-rw-rr 1 sxu staff 9 Aug 2 12:52 b.c-rw-rr 1 sxu staff 9 Aug 2 12:52 file1.c-rw-rr 1 sxu staff 9 Aug 2 12:53 file2.c |
(Continued next page)
Task B
Write a shell script (to run on the Bourne shell) that runs an infinite loop to monitor which users on a denial list have logged into the UNIX system more than once.
(1). The denial list must be stored in a text file named user.deny which lists which users are not allowed multiple logins, specified by one username per line.
(2). In the beginning of the script you need to check that the user.deny file exists under the current directory, and if not, your script displays a message to say so and then exits.
(3). Every 3 seconds, the script must display a warning message to report users on the denial list who have logged in multiple times. Display the users full name instead of his/her username in the warning message.
(4). Its unnecessary for your script to handle the situation where a user logs in and then logs off immediately (i.e. within a 3 second interval).
Your script for this task must be named mlog.sh. The following is a sample output of the script (It is OK if the script leaves behind temporary files when it is finally interrupted). The $ is the shell prompt.
| $ ./mlog.sh No user on the user.deny list has multiple logins No user on the user.deny list has multiple logins The user John Smith (on the denial list) has logged in more than once!The user Adam Jones (on the denial list) has logged in more than once! No user on the user.deny list has multiple logins No user on the user.deny list has multiple logins The user David Monks (on the denial list) has logged in more than once!The user Nick Andrews (on the denial list) has logged in more than once! |
Task C
Dominion Consulting in Sydney needs a shell script (to run on the Bourne shell) to maintain its employee records file, which contains the following information about each employee: telephone number (8 digits, first digit nonzero), family name (alphabetic characters), first name (alphabetic characters), department number (2 digits), and job title (alphabetic characters). This script should let users add, delete, search for, and display specific employee information.
(1). Create a text file named records containing the following records with fields delimited by colons:
95671660:Jones:Sarah:45:sales manager
93272658:Smith:John:43:technical manager
98781987:Williams:Nick:35:computer officer
99893878:Brown:Sarah:12:electrician
95673456:Couch:David:26:chef
95437869:Anderson:Sarah:19:CEO
(2). In the beginning of your script you need to check to see whether the required text file (records) actually exists under the current directory (if not, your script displays a message and then exits).
(3). Your script (must be named menu.sh) will present a menu of operations that a user may choose from. Among other tasks, these operations automate the following four activities:
- Displaying all current employee records on the screen.
- Searching for and displaying specific employee record(s) (search all fields, ignoring case)
- Adding new records to the records
- Deleting records from the records
(4). Your script must produce the following menu:
Dominion Consulting Employees Info Main Menu
============================================
- Print All Current Records
- Search for Specific Record(s)
- Add New Records
- Delete Records Q Quit
(5). After a 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.
(6). You must validate the employee details when adding a new record.
(7). A valid family name, first name and job title must be alphabetic characters and/or spaces. The first digit of a valid phone number (of eight digits) must not be zero. Each telephone number must be unique. A valid department number must only contain 2 digits.
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.
$ ./menu.sh
Dominion Consulting Employees Info Main Menu
============================================
- Print All Current Records
- Search for Specific Record(s)
- Add New Records
- Delete Records
Q Quit
Your Selection: 1(user input)
95671660:Jones:Sarah:45:sales manager
93272658:Smith:John:43:technical manager
98781987:Williams:Nick:35:computer officer
99893878:Brown:Sarah:12:electrician
95673456:Couch:David:26:chef
95437869:Anderson:Sarah:19:CEO
Press Enter to continue (user presses Enter here)
Dominion Consulting Employees Info Main Menu
============================================
- Print All Current Records
- Search for Specific Record(s)
- Add New Records
- Delete Records
Q Quit
Your Selection: 5(user input)
Invalid selection
Press Enter to continue (user presses Enter here)
Dominion Consulting Employees Info Main Menu
============================================
- Print All Current Records
- Search for Specific Record(s)
- Add New Records
- Delete Records
| Q Quit Your Selection: 2(user input)Enter keyword: Sarah (user input)95671660:Jones:Sarah:45:sales manager99893878:Brown:Sarah:12:electrician95437869:Anderson:Sarah:19:CEO Press Enter to continue (user presses Enter here)Dominion Consulting Employees Info Main Menu============================================1 Print All Current Records2 Search for Specific Record(s)3 Add New Records4 Delete RecordsQ Quit Your Selection: 2 (user input)Enter keyword: Monks (user input)Monks not found Press Enter to continue (user presses Enter here)Dominion Consulting Employees Info Main Menu============================================1 Print All Current Records2 Search for Specific Record(s)3 Add New Records4 Delete RecordsQ Quit Your Selection: 2(user input)Enter keyword: (user simply presses Enter without typing in anything)Keyword not entered Press Enter to continue (user presses Enter here)Dominion Consulting Employees Info Main Menu============================================1 Print All Current Records2 Search for Specific Record(s)3 Add New Records4 Delete RecordsQ Quit Your Selection: 3(user input)Add New Employee RecordPhone Number (xxxxxxxx): (user simply presses Enter without typing in anything)Phone number not enteredPhone Number (xxxxxxxx): 00123456 (user input)Invalid phone numberPhone Number (xxxxxxxx): 95437869 (user input)Phone number existsPhone Number (xxxxxxxx): 99887766 (user input)Family Name: abc123 (user input)Family name can contain only alphabetic characters and spaces |
| Family Name: Warren (user input)Given Name: Tony5 (user input)Given name can contain only alphabetic characters and spaces Given Name: Tony (user input) Department Number: 123 (user input)A valid department number contains 2 digitsDepartment Number: 23 (user input)Job Title: accountant1 (user input)Job title can contain only alphabetic characters and spaces Job Title: accountant (user input) Adding new employee record to the records file New record saved (display this only after saving record is successful) Add another? (y)es or (n)o: n (user input) (Note: if the user answer is y here then the above procedure is repeated) Dominion Consulting Employees Info Main Menu============================================1 Print All Current Records2 Search for Specific Record(s)3 Add New Records4 Delete RecordsQ Quit Your Selection: 4(user input)Delete Employee Record Enter a phone number: 05671660 (user input)Invalid phone numberEnter a phone number: 99999999 (user input)Phone number not foundEnter a phone number: 95671660 (user input)95671660:Jones:Sarah:45:sales manager Confirm deletion: (y)es or (n)o: y (user input)Record deleted. (This message is displayed only after this record has been successfully deleted from the records file)(If the user answer is n then the main menu is displayed again. Then if the user enters Q or q then the script is terminated.) |
(Continued next page)
For All Your Scripts
You must x Include your full name, student ID, and a brief introduction of what the script does in all your shell scripts, as a comment in the beginning of each script.
x Make your scripts run on the Bourne shell, regardless of which shell the user of your scripts is currently on.
x Add in-line comments to help other people understand your scripts.
x Use
where appropriate to make the output of your scripts more readable.
x Note that your script structure and layout are also important as they will be marked as part of the assessment process.

![[Solved] KIT104 Assignment2 UNIX Shell Programming](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] KIT104 Assignment2 UNIX Shell Programming](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.