Question: Using for/while This script will do two simple loops. First it will backup from a list of files, and then wait for a file to

Using for/while

This script will do two simple loops. First it will backup from a list of files, and then wait for a file to become readable. Name this script backWait.sh

#!/bin/sh # some comment for file in $(cat filelist) do cp $file $file.bak done while true ; do [ -r $1 ] && break sleep 1 done

Create a file named filelist with four filenames in it: file1, file2, file3, and file4. The names only need be separated by whitespace. Create file1 and file3 by using touch (e.g. touch file1). The touchcommand updates a files current timestamp. If the file does not exist touch creates a zero length file with the current timestamp.

Create another file that has no read attributes. For example the file name could be noread. To change that file so no one has read ability use the command: chmod -r noread.

Run the backWait.sh with the file name for the noread file as a parameter: i.e. backWait.sh noread. The script should then attempt to backup the listed files in filelist. Note that it will fail for those that do not exist. The script will then wait for noread to have read attributes.

Open a second terminal or command prompt. Change the file noread to have read permission using the chmod command. Read the man page for chmod to determine the syntax to add read permission to a file.

LR(13/16): (2 pts.) The script running in the first terminal window should then complete. Document that the backup worked.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!