Lab Assignment--Shell Scripts
Your task is to create a tcsh shell script that is able to backup all the C program files in your current directory.
The algorithm is as follows:
- If a backup directory does not exist, then prompt the user if they would like to make one.
- If the user responds "y" or "yes" in either capitals or lowercase, then make the backup directory (in your current working directory)
- If the user responds "n" or "no" in either capitals or lowercase, then produce a message that no directory was created
- otherwise, print a message that an invalid response was entered
- If the backup directory was successfully created (ie. it exists)
- For each .c file:
- If there have been changes to the file since the last backup, then copy the current .c file to the backup directory and print a message that the
file has been updated
- Else (if no copy exists in the backup directory) copy it and print a message that the file had no previous copy and is now backed up
- (Otherwise, no copy will be made)
The following is a shell script that makes backups to a "backup" directory in your home directory: bckup.sh
You might want to take ideas from it, but note that it does not prompt you if you would like to make the directory.
Please include print messages in your script to indicate if the file was not previously in the backup directory or if the file existed before and is just being updated.
Submit 2 files to URCourses:
- code of tcsh shell script
- script of the run showing the test cases outlined below
Test Cases captured in a "script":
- Start by removing your backup directory (rm -r backup)
- Ensure that there are some .c files in the current directory
- Show the directory using ls -l
- Run the backup script several times as specified below:
- Type "NO" to creating a backup directory
- Type "n" to creating a backup directory
- Type "up" to creating a backup directory
- Type "yes" to creating a backup directory
This should create the directory and copy files
- ls -l backup
- Remove the directory (rm -r backup)
- Type "Yes" to creating a backup directory
- Remove the directory
- Type "y" to creating a backup directory
- Append to all the files and rerun your backup script
an good way to append is to type: echo "something" >> file.c
- Append to one file and rerun your backup script
- Touch a few existing files and rerunning the script.
Depending on your implementation, this might not do anything.
- Create a new .c file (using touch) and rerun your backup script
- Do not create a zip file
- Submission is on UR Courses
- Submit your own work
- Be mindful that your assignment is due two hours before the start of your next lab