Question
Use for and while loops in CLI. 2. Task automation using at and cron commands. 3.1. In the left pane, process the contents of /etc
2. Task automation using at and cron commands.
3.1. In the left pane, process the contents of /etc directory to print filemode, filesize, and filename of text files using a for loop, command substitution, and pipes.
a) Use ls -1 /etc when creating the list in the for statement.
b) In the body of the loop, use test command to see if the entry is a file or a directory. Proceed only if it's a file, ignore if it's a directory. Note that you will need to prepend /etc to filename because ls -1 returns only the filename as in ls -l /etc/$_FNAME.
c) Use tr command to squeeze multiple blanks into one blank in each line, like tr -s' ' .
d) Use cut command to select individual fields in an input line.
e) Use tr command again to translate field separator, aka delimiter, blank to a tab as in tr ' ' 't' .
f) 0pts. Use head command to limit the size of listing.
4. 15pts. Using while loop in CLI to read from a file :
4.1. In the right pane, read the contents of ls.etc file to print filemode, filesize and filename of text files using a while loop.
a) Save the output from ls -l /etc command in a file ls.etc .
b) Use a while loop to read ls.etc line by line into a variable _LINE.
c) Use echo command to pipe the output to cut command to select the fields to print.
d) Replace delimiter blank with tab character.
e) Use grep to filter in only the lines that don't have a d in the first position as in grep -v ^d .
f) 0pts. Use head command to limit the size of listing
5. 10pts. Task scheduling using at :
5.1. Create a shell script 300*.at which
a) tests if a file /tmp/norun does exist. If yes, it will echo removing /tmp/norun with a timestamp of the form YYYYMMDD-HH:MM:SS to 300*.log (hint: use %Y%m%d-%T format of the date command) and remove /tmp/norun .
b) reschedules itself to run 5 minutes later using at command.
5.2. Create a cron entry to run a script 300*.crn every 1 minute every day of every month. . The script will
a) test if /tmp/norun exists. If yes, it will echo not running with a timestamp as in 5.1.a to 300*.log , and exit with return code 2.
b) otherwise, create /tmp/norun and echo Hello world with a timestamp as in 5.1.a to 300*.log .
5.3. Run 300*.at script manually. Schedule 300*.crn using crontab -e as a regular user.
5.4. Run atq command to see if your script has been scheduled.
5.5. Wait long enough you accumulate log messages in 300*.log . Display the first 20 lines in 300*.log
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