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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started