NATIONAL UNIVERSITY OF COMPUTER AND EMERGING
SCIENCES ISLAMABAD
O PERATING SYSTEMS SPRING 2020
ASSIGNMENT 01
Shell Scripting
Instructions
• -500% marks will be awarded to the students involved in plagiarism.
• All the submissions will be done on google classroom. .
• Implement the assignment using Bash Shell Script.
QUESTION NO. 01
Write a script that takes two parametric variables:
./script pattern_option number
where
pattern_option = {left, right, full}
and output the pattern depending on the input parameters as shown in Fig 1.
Generate error messages for invalid input parameter.
Figure 1: Output for number=5
Operating Systems Spring, 2020 NUCES, Islamabad
QUESTION NO. 02
Write a script that displays a main menu and perform tasks based on the in-
put value. Valid input values = {1, 2, 3, 4, exit}.
The different options 1,2,3,4 will display the output as follow:
1. Input a filename from user and display permissions of that particular file.
Then invert the permissions e.g. If permissions were r-x change them to
-w-. Then again display the updated permissions of that file.
2. Input a filename and a string and search it in the file. Output the lines of
file where that string is found. But if the string contains a dot(.) it mean any
character can fill the place. For example:
string = c.t ={cat, cot, c t, }
3. Create a file [Link] and add the content of all the files in the current
directory to dummy. But copy the content in such a way that if
files in current directory = {f1, f2, f3, f4,. ... ,fn}
Then copy first N lines of files at even location {f2,f4,. } and last N lines of
files at odd location {f1,f3,. }. Input value of N from user.
4. Input a filename from user and check modified date of that file. If modi-
fied date is greater than 24 hours from the current time change the modi-
fied date to current date. Along with displaying the output on terminal,
maintain a logfile that contains the information of the script. Format of
the logfile is given on the next page:
2
Operating Systems Spring, 2020 NUCES, Islamabad
Format of the logFile
Option 01 selected at date and time
File name: [Link]
Permissions of [Link]: Show permissions
Permissions changed
Updated Permissions of [Link]: Show permissions
Option 02 selected at date and time
Filename: [Link]
String: string
Output all the lines in filename where string is found.
Option 03 selected at date and time
Files at odd location: f1, f3, f5
Files at even location: f2, f4
[Link] is created and N lines of each file copied in it.
Option 04 selected at date and time
Filename: [Link]
Current modified date: date
Modified time updated or not
Option exit
Script terminated at date and time.
QUESTION NO. 03
Fig 2 shows the basic hierarchy of the files. Input (read) the name of the Main
Directory. In the Main Directory there are multiple directories Dir_1, Dir_2,...... ,
Dir_N. In each subdirectory there are multiple files with different extensions.
Now insert a loop that takes a string value as input and terminate when user
enter any string starting with e. The hierarchy of the files will change when user
will enter either forward or backward
3
Operating Systems Spring, 2020 NUCES, Islamabad
Figure 2: Hierarchy of the main directory
1. forward
Create 5 different directories namely java, txt, cpp, cc and other. Copy each
file in the directories depending on their file extension. Before copying the
file follow the protocol to name the file as [Link].
Delete all the extra folders from main Dir namely Dir_1, Dir_2,. , Dir_n.
2. backward
Now in the backward cycle, extract name of directories from the file name.
Create the directories again and copy the files to their original directory
restoring their default names.