Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. [10 points] Write a BASH script bkUp.sh containing a function backupfile that takes a file name as argument and backs up that file in

image text in transcribedimage text in transcribed

3. [10 points] Write a BASH script bkUp.sh containing a function backupfile that takes a file name as argument and backs up that file in the directory /tmp/\$USER which allows any user to use the script without modifications. A sample interaction is shown in Listing 5. Note: Notice in the case of /etc/hosts/ that the backup file has only the file name, not full path. Note: The Linux environment variable USER represents will represent the login name of the user issuing the command. If the script is called with an incorrect number of arguments, it returns an error code 4 . If the file provided as argument is a directory, the script should exit with error code 3 ; if it doesn't exist, the script should return error code 5; if the backup was unsuccessful, it should return error code 1. The name of the backed up file should be the name of the original file, followed by the date and time of backup (separated by underscores), and ending in ".bk" (see Listing 5). Use your script and its function backupfile to create backups of the following files: - /etc/hosts - bkUp.sh In readme.txt, provide evidence that you were able to backup these two files. Listing 5: Backup script interaction on Polaris \$ ls /tmp/fhussain Is: cannot access'/tmp/fhussain': No such file or directory $ ls bkUp.sh $./bkUp.sh /etc/hosts $ echo $ ? 0 $./bkUp.sh bkUp.sh $ echo $? 0 $ ls /tmp/fhussain/ bkUp.sh_22Jan23_2033.bk hosts_22Jan23_2033.bk $./bkUp.sh /etc/host3 /bkUp.sh: File /etc/host3 does not exist. Quitting. \$cho $? $./bupsh usage:./bkUp sh pathToFile>. Quitting $ echo $? 3 Note: As can be seen from Listing 5, either the full path to the file must be given or the file will be assumed to be in the current directory. There was no file /etc/host3 resulting in the exit status 5 from the script. Also, an attempt to backup the home directory also failed (with exit status 3 ) as it is a directory. Note: If the file already exists in /tmp/\$USER (which is unlikely given the timestamps), you can simply overwrite it. Note: You might find the following commands to be helpful in writing the script: basename(1) and date(1). Deliverable: bkUp.sh, readme.txt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

ISBN: 0764549634, 9780764549632

More Books

Students also viewed these Databases questions