Sei sulla pagina 1di 3

Wase Assignments System Programming

Course
Unix Shell Scripts

1. Write a script that behaves both in interactive and non interactive mode.
When no arguments are supplied , it picks up each C program from the
current directory and lists the first 10 lines . It then prompts for deletion of
file . If the user supplies arguments with the script, then it works on those
files only.

2.Write a script that looks up every .c file in the current directory for the
strings printf or
fprintf. If found the script adds the statement # include <stdio.h> at the
beginning of the file
but only if it doesnt already have it included.

3. Write a script that checks each minute and reports on who logs in and who
logs out.

4. Assume that you have a number of files , downloaded from the internet,
in the /home/kumar/download directory. The table of contents ( TOC) is
available in the file
TOC_download.txt in the form Filename:description. The script should check
each file in the
download directory that doesnt have a description in the TOC file and
prompt the user for the
description. The TOC should be updated to maintain the list in sorted
condition. The script must be immune to signals.

5.You have a number of C programs that contain comment lines at the


beginning of each program. The lines begin with a /* followed by the first line
comment , but the terminator has
*/ as the only characters in the line. Remove these comments from all files.

6. Write a script to display a menu and depending on the selection display


the free disk space, free disk memory or exit. Df is for free disk space; free is
for free memory. The menu program should exit only of selection is made.
Display "PROGRAM MENU"

Display "1 - display free disk space"


Display "2 - display free memory"
Display 0 - exit program"
Display "Enter selection:
Invoke a function Enter which would display press enter to continue after
the selection is made.

7. Write a script to check for the files entered, whether it is a Regular file, or
is it a directory file , whether it is a writable file and if not all of the above
display it is not writable.

8. Devise a script that takes a filename as argument ( which must exist in the
current directory)
and locates from your home directory tree all pathnames of its links. The
list should be
mailed to self.

9.Write a script to copy files to a directory only when they dont exist there.
The filenames are
supplied as arguments and the last argument is the directory.

10. Write a shell function that locates a directory supplied as argument in


the home directory
tree and switches to it. Will the same code work if placed in a shell script.

11. Write a shell function size() which lists only the total size of the files
supplied as arguments
( all files without arguments).

12. Write a shell script that receives two file names as arguments. It should
check whether
the two files contents are same or not. If they are same then second file
should be deleted.

13. Write a shell script which will receive any number of filenames as
arguments. The shell script should check whether such files already exist. If
they do so then it should be reported.
If these files do not exist then check if a sub directory called mydir exists in
the current directory. If it doesnt exist then it should be created and in it the
files supplied as arguments
should get created. If mydir already exists then it should be reported along
with the number of
files that are currently present in mydir.
14. Write a shell function mkcd() which would create all the directories
present in the path supplied to it as argument and change over to the last
directory in this path. Thus
$ mkcd d1/d2/d3/d4/d5
should create the five nested directories and change the present working
directory to d5.

15. Write a script to compare the files in two directories and lists which files
in the first directory are missing from the second. The directories are passed
as arguments to the script.

16. Write a script to convert the specified filenames to lower case. Any
number of filenames
can be passed as arguments to the script.
All exception scenarios if any to be handled by the script (like if for
example
If any file exists in upper case name exists aprior to conversion in the
same path, or if a file does not exist in that path , then obviously mv will fail
for both of this cases)

Potrebbero piacerti anche