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

Assignment_2 (2)

This document outlines the assignment details for the CSE332 Operating Systems Lab at Ahmedabad University, focusing on shell programming. It includes instructions for submission, a breakdown of two parts with specific tasks, and requirements for script writing on a Unix/Linux platform. Students must complete a total of 20 questions from the provided tasks, adhering to submission guidelines.

Uploaded by

varun.p3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment_2 (2)

This document outlines the assignment details for the CSE332 Operating Systems Lab at Ahmedabad University, focusing on shell programming. It includes instructions for submission, a breakdown of two parts with specific tasks, and requirements for script writing on a Unix/Linux platform. Students must complete a total of 20 questions from the provided tasks, adhering to submission guidelines.

Uploaded by

varun.p3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Ahmedabad University

School of Engineering and Applied Science B.Tech (CSE),

Course: CSE332- Operating Systems Lab

Assignment - 2, Shell Programming

Instructions and Important note:

A:Write and test shell scripts/programs on Unix/Linux platform.

B:Date of submission: 23/08/24 11:59:59 (for all section) in LMS only.

C: This assignment have two parts part-1 and part-2 ,first part consist of 12 different types question,
and part-2 consist of 13 different types questions out of which you have to do a minimum of 10
questions from each part ie a total of 20 questions for final submission.

D:Attempt problems related to one part at same place with appropriate sr.no.

E:While submitting your file follow the convention:Roll No_Name_Assignment No.

F:Submit a pdf file consisting code of script followed by the output window of your terminal.

Part-I

1-Write a shell script to calculate the factorial value of a number.

2. Write a shell script to generate Fibonacci series.

3. Write a shell script to draw a Pascal’s Triangle.

4- Write a shell script that first displays the total number of arguments passed to it using $# and
checks if exactly 3 arguments were given, if not, it outputs an error
message and exits with a status code of 1, indicating an error,if 3
arguments are passed, the script prints each argument along with its
position.

5- Write a shell script to print a number in reverse order which should support the following
requirements:
a. The script should accept the input from the command line.
b. If we don’t input any data, then it displays an error message to execute the script correctly.

6-write a shell script to find the unique words in a file and also count the occurrence of each of these
words.
7- Write a shell script to perform the following user operations:
a. Print sorted list of users

b. Count total number of users

c. Search for any specific user and display no. of times the user logged in

d. Check if any specific user is terminally active e. List all users without password.
(Hint: Use Pipes to achieve the result)

8-Write a shell script to declare an array, (with at least 5 elements), assign values to it, and access its
elements which is having underwritten functionality (array elements can be strings, numbers, or a mix
of both)

a. Access and display individual elements of the array by their index.


b. Print the entire array.

c. Uses loop to iterate through all the elements of the array and print each element with its
corresponding index.

9-write a shell script using function, declare at least three functions in the script which perform
following task

a. A function that takes a user name as an argument and prints it on terminal.

b. A function that takes two numbers as arguments, calculates their sum, and returns or prints the
result.

c. A function that calculates the factorial of a given number using a loop.

10-Write a shell script to read a directory name and delete all zero-sized file from it and its sub-
directories.

11-Write a shell script to compare identically named files in two different directories and if they are
the same, copy one of them in a third directory.

12-Write a shell script to display all files in any specific directory (read from the user) in the following
format:

File Size (in kB) Date Security Owner user

test 6 1 Jan -rw-rw-r-- user

Also, display the total number of files and total space occupied by directory.

Part-II

1-Write a shell script that determines if a specific word exists in a given line of a file the script will
search for the word in each line of the file and indicate whether the word was found,script checks if
exactly two arguments are provided, filename and the word to search for, if not, it prints a usage
message and exits.

2-Write a shell script to read the name (or path) of 2 directories and copy all the files from them into
a new directory.

3-write a shell script that determines the operating system (OS) of the machine it is running. (use pipe
and switch case only)
4-Write a shell script and use for loop to move all the files in the current directory to another specified
directory.

5-Write a shell script to display the date, time and greeting message (like Good Morning User etc.) The
time should be displayed with “AM” or “PM” and not in terms of 24-hour notation.

6- Write a shell script that prompts the user to enter three numbers. use nested if-else statements to
compare the three numbers and determine:

a. The largest number.

b. Whether all three numbers are equal.

c. Whether any two numbers are equal.

7-Write a shell script to read the name of a directory and display the name of all executable files in the
given directory. Also, display the total count in the end.

8-Write a shell script to check if directory exists and if it exists, display list of files and directories (along
with subdirectories) in it.

9-Write a shell script to validate password strength, consider some assumptions for the password
string as given below.

a. Length – minimum of 8 characters.

b. Contain both alphabet and number.

c. Include both the small and capital case letters.

If the password doesn’t comply with any of the above conditions, then the script should report it as a
<Weak Password>.

10-Create a shell script that uses the select loop to present a menu of options to the user. The script
should handle user input in dignified way, perform actions based on the selected option, and allow the
user to exit the script when desired.

1. Menu Options: The script should present the following options:

1. Display the current date and time.

2. List files in the current directory.

3. Display the current user.

4. Exit the script.

2. Prompt Message: Use a user-friendly prompt message for the menu options. For example,
"Please select an option (1-4): ".

3. Handle User Choices: Implement actions for each menu option:

o For option 1, display the current date and time.


o For option 2, list files in the current directory.

o For option 3, display the current user.

o For option 4, exit the script with a message saying "Goodbye!".

11-Create a shell script that demonstrates various forms of input and output redirection, script should
perform several tasks, using redirection to manage file input and output.

Script should perform the following underwritten tasks:

1. Create a File: Create a file named out.txt and write some initial content to it.
2. Append to File: Append additional content to out.txt based on user input.
3. Read from File: Read and display the contents of out.txt.

12-Create a shell script that takes input from command-line arguments to perform various tasks, it
should handle different types of input, validate them, and use them to execute specific commands or
operations.

Functionality of script:

o Display Help: If the user provides --help or -h as an argument, display a help message
that describes the script's usage.
o Display Current Date: If the user provides --date or -d, display the current date and
time.
o List Files: If the user provides --list or -l followed by a directory path, list the files in
the specified directory.
o Count Lines in a File: If the user provides --count or -c followed by a file path, count
the number of lines in the specified file.
o Error Handling: Handle cases where required arguments are missing or invalid

13- Write a shell script which reads a text file and output the following:

a. Count the number of characters, words and lines

b. File in reverse order

c. Frequency of any particular word in the file

d. Replace Lower case alphabets in place of Upper-Case Alphabets

You might also like