0% found this document useful (0 votes)
327 views

OS Assignment#1 Spring2020 PDF

The document provides instructions for three assignments involving shell scripting. Assignment 1 requires writing a script that takes parameters to output different patterns. Assignment 2 involves a menu-driven script to perform file operations like changing permissions, searching files, concatenating files. Assignment 3 deals with reorganizing files into different directories based on extensions and then reversing the process. Input validation and error handling is required. A log file format is also specified.

Uploaded by

Usama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
327 views

OS Assignment#1 Spring2020 PDF

The document provides instructions for three assignments involving shell scripting. Assignment 1 requires writing a script that takes parameters to output different patterns. Assignment 2 involves a menu-driven script to perform file operations like changing permissions, searching files, concatenating files. Assignment 3 deals with reorganizing files into different directories based on extensions and then reversing the process. Input validation and error handling is required. A log file format is also specified.

Uploaded by

Usama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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 dummy.txt 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: filename.txt
Permissions of filename.txt: Show permissions
Permissions changed
Updated Permissions of filename.txt: Show permissions

Option 02 selected at date and time


Filename: filename.txt
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
Dummy.txt is created and N lines of each file copied in it.

Option 04 selected at date and time


Filename: filename.txt
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 DirectoryName-Filename.extension.
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.

You might also like