Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a script to backup a list of files in C shell Create a file and type in th

ID: 3859282 • Letter: W

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) 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 argv’s etc ($0 is okay)

bash or ksh if’s with (( )) or [[ ]] or [ ]

Explanation / Answer

The required script will have two main levels:

1) Traversing the desired directory. Each file in the directory should be traversed.

2) Copying/making a back up of the file in the backup diretory.

backup.sh

prompt line: backup.sh directory1 backup.txt

for entry in "$1"/*

    do

         cp "$entry" "$2"

    done

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote