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

ITWS2 Assignment - 1 Shell Scripting

This document provides instructions for 5 Bash shell scripting assignments: 1. The average_files.sh script finds files larger than the average size in a directory by calling functions to calculate the average size and find matching files. 2. The num_sort.sh script sorts a list of command line arguments in ascending numerical order without using built-in sort functions. 3. The roman.sh script converts numbers to Roman numerals by taking a number as a command line argument. 4. The userlist.sh script lists all users on the system by parsing the /etc/passwd file with awk. 5. The time_ping.sh script pings google.com the number

Uploaded by

pooja
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)
53 views

ITWS2 Assignment - 1 Shell Scripting

This document provides instructions for 5 Bash shell scripting assignments: 1. The average_files.sh script finds files larger than the average size in a directory by calling functions to calculate the average size and find matching files. 2. The num_sort.sh script sorts a list of command line arguments in ascending numerical order without using built-in sort functions. 3. The roman.sh script converts numbers to Roman numerals by taking a number as a command line argument. 4. The userlist.sh script lists all users on the system by parsing the /etc/passwd file with awk. 5. The time_ping.sh script pings google.com the number

Uploaded by

pooja
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/ 2

ITWS2 Assignment -1

Shell Scripting
1. Write a Bash script, average_files.sh, to find all the files and
directories with size larger than or equal to the average file size of
the directory. Say, the directory /home/student has 6 files/directories
with size in parentheses " x(100) y (10) z (100) p (100) q(20) r(66),
your program average_files.sh /home/student" will list "x z p r" since
the size of each of the four files/directories is larger than the average
file size of 66(note that the average is rounded off) .

Use three functions: main, average, and find_files, where main


calls average and find_files, the average computes the average
file size of a directory and find_files looks out for files with size
greater than the average.

2. Write a Bash script, num_sort.sh, that can sort a list of command line
parameters in ascending order. There is no limit to the number of
arguments passed as list parameters. For example, your command
will look something like:
$ num_sort.sh 8 27 9 -2 7 92 -9 0 and type enter.
Your program will return: -9 -2 0 7 8 9 27 92

Use only basic commands and array. Do not use any built-in
commands that sort array.

3. Write a Bash script, roman.sh, to convert a number to Roman


number. The function takes the input number as a command line
argument. You can assume the range of the input to be 0-150,
however bonus points will be awarded for having larger range.
The command to run will look like:
$ roman.sh 77
Your program will return: LXXVIII

4. Write a Bash script, userlist.sh, to list all the users on the system.
The command to run will look like:
$ userlist.sh
Return:
USER #1 = root
USER #2 = bin
USER #3 = daemon
...
USER #33 = bozo
Hint: Use the contents of the file /etc/passwd and awk.

5. Write a shell script, time_ping.sh, to ping google.com n times only.


Also the output of ping should be timestamped. n will be given as a
command line argument. The output at each consecutive lines
should have a different color.

E.g.

Here you have pinged google 5 times as given in the command-line


argument and also each output line of ping has a timestamp with it. E.g
Fri Jan 22 00:32:39 IST 2016 in the first line.

You might also like