Question: Write a script to backup a list of files in C shell Create a file and type in the list of files (in your directory)
Write a script to backup a list of files in C shell
Create a file and type in the list of files (in your directory) that you want to backup.
Create a directory in which you will store the backed-up files.
Script Name: backup.txt
Arguments: A filename and directory. The filename holds the list of the files that should be backed-up. The directory is where the backed-up files should be stored.
Validation: The minimum validation requirements are:
Ensure that exactly two arguments are entered.
Check that the first argument is the name of a file that exists.
Check that the second argument is the name of a directory that exists.
Body Section: Create backup files for all the files listed in the first argument. The backup files should have the same name as the original file with the extension .bak. They should be copied to the directory given as the second argument. the backup MUST be done inside a loop. Also, the command (line) that copies the file needs to place the copy in the given directory and rename it to .bak. Use a foreach loop to cycle through the list of files and copy them. You should be able to do the copy to the new directory and rename in one line (in the same command).
Testing the Script
Test the script with no arguments
Test the script with one argument.
Test the script with three arguments.
Test the script with two arguments the first not being the name of a file.
Test the script with two arguments the second being the name of a file, not a directory.
Test the script with the name of the file and directory that you created.
Testing the Effect of the Script
Check the contents of the directory to be sure the files were copied.
NOTES: Should never exit 0 in middle of code you should make it to the end of the script for exit 0. Nesting is probably not needed, the exit statements take care of that. Use standard C Shell. I do not want to see:
while loops
fi
$1, $2 for argvs etc ($0 is okay)
bash or ksh ifs with (( )) or [[ ]] or [ ]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
