Sie sind auf Seite 1von 4

Wase Assignments System Programming

Course
Unix Shell Scripts

Group1

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.

Group 2

Assignment 3

Write a script (Exercise3.sh) to prompt for digit, letter and if it is not digit or
character display an error. Prompt for type a digit or letter. If [A-Z or A-z] is
typed display you typed the character characterIf [0-9]digit is typed
display you typed the digit digit, otherwise display you did not type a letter
or a digit. Hint use case statement.

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

Group 3

5. 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.
6. Write a script (Exercise4.sh) 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. Hint: Use a Until statement

Display"PROGRAM MENU"
Display "1 - display free disk space"
Display "2 - display free memory"
Display ""
Display 0 - exit program"
Display ""
Display "Enter selection:

Invoke a function Enter which would display press enter to continue after
the selection is made.

Group 4

7. 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.

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.

Group 5

9. Write a script(Exercise 5.sh) to check for the files entered, whether it is a


Regular file, it is a directory file , whether it is a writable file and if not all of
the above display it is not writable.
The script may accept many files as arguments. i.e you may want to test it
with more than 1 file.

Hint : use for and if statement.


10. 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.

Group 6

11. Write a shell script named exrercise1.sh that it accepts a file or directory
as an argument and it displays the contents of a file if it is a file and lists the
contents of a directory if it is a directory. Display enter a file name or
directory name> in a new line to accept the file name.

12. . 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.

Group 7

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

14. 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.

Group 8

15. 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.
16. 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.

Das könnte Ihnen auch gefallen