CSCI 251 Systems and Networks

Lab10 Bourne Shell Scripting Exercises

Wednesday March 31, 2010


Task #1: Design, implement and test Bourne shell scripts to perform the given tasks

Create test files and directories as needed for testing your scripts. Use the echo command abundantly during test phase to show what the script would do without actually running the commands. Use comments to describe what the script is doing, what the assumptions are and also to describe what improvements are desirable.

Exercise #1

Write a shell script to read a set of file names and display each file name appended with '.bak'. Name your script scr1. Make it executable by running

chmod +x scr1

Run the script and test. Try

./scr1 foo bar baz.C
./scr1 *

and see if it works as expected.

Exercise #2

Write a script to display date and time every five seconds. Name it scr2. You will use Ctrl-C to exit the script.

Exercise #3

Write a script to find all executable files and append '.x' to all filenames that do not already have that extention. Name your script scr3.

Write a script to do the reverse. i.e., it will remove '.x' extention (once) from file names of all executable files.  Name your script scr3-1

Exercise 4

Create a script named scr4 that makes a backup of all files in a certain 'project' directory by creating a tar file and storing it in a designated 'backup' directory.

The script should check whether the backup directory exists. If it does not, the script should display an error message and exit with exit status 1. The tar file must be of the form timestamp_proj.tar where timestamp is in the format ddmmyyyy-hhmmss.

(Hint: Create your own 'project' and 'backup' directories and populate with files for testing purpose. Within the script, use shell variables to hold the locations of those directories.)

Task #2: Submit your work

Put all your scripts into a single text file username-lab10.txt clearly separating one from another and mail it to

before 8:00am Monday April 05, 2010.