Question One . Create a count-down timer using shell script. The user sets the timer in minutes and seconds and the timer starts to tick. Once it is reached to zero, a message should be displayed on...

1 answer below »


Question One .
Create a count-down timer using shell script. The user sets the timer in minutes and seconds and the timer starts to tick. Once it is reached to zero, a message should be displayed on standard output. When the timer gets less than three minutes, then in each minutes, it should display the remaining time on standard output, i.e. “Three Minutes Remaining”, “Two Minutes Remaining”, “One Minute Remaining”.


The time has to be passed as a command line argument. Name your script “timer.sh”.



Example:
A call “timer.sh 5,35” sets up a timer to 5 minutes and 35 seconds.





Question Two.
Create a script to count the total size of all files in a given directory. The name of this directory has to be passed as command line argument and your script should work recursively, i.e. counts total size of all files in this directory and all directories(, sub, sub-sub, …) under this directory. Your output must include the number of counted files along with their total size, e.g.
“Total files: 78, Total Size=78 MB”.



Question Three.


Develop a shell script that counts the total sum of all words used in all the ‘.txt’ files of the current directory and print the output in a file. Name this file as current date-time followed by “_report.txt. for instance,

“Sun-Apr-3 14:04:13_report.txt”
.




Question Two.


Suppose that there are two shell-scripts that produce output forever (infinite loop), namely

one.sh

and

two.sh
. For each of the following, write down the command(s) to accomplish the following:


a. Start both processes in the background


b. Bring
“one.sh”
processes to foreground


c. Move “two.sh”
to foreground and
“one.sh”
to background


d. Move
“two.sh”
to background


e. Pause both processes in the background


f. Resume both processes in the background


g. Kill both processes in the background




Question Three


Develop a shell script that monitors any changes made to the size of each and every file in a specific directory at all times. The directory is passed as a command line argument. For any changes that is made to the size of any file, display a quick notification to standard output: “Modification has been made!”. Also, display the name of the file that has been modified.


Name your script “monitor.sh”
and
let it run in the background at all times. Then test your script to make sure that it works as desired.



Monitor.sh ~/Assignment_Two/Test_One




Hint:




You can use command ‘ls’ and store the results in a file, name it output_one.txt. Right after, run command ‘ls’ again, but this time, store the results in a different file output_two.txt. Now, compare these two files by using ‘diff’ command. Finally, place this algorithm in an infinite loop and let it work in the background forever.

Answered Same DayJul 14, 2022

Answer To: Question One . Create a count-down timer using shell script. The user sets the timer in minutes and...

Aditi answered on Jul 15 2022
78 Votes
SOLUTION
Answer 1:
#!/bin/bash 
if [ $# -ne 2 ]; then 
echo "Error: Invalid number of arguments." 
echo "Usage: ./timer.sh
exit 1 
fi 
min=$1 
sec=$2
 if [ $min -e q 0 ] && [ $sec -e q 0 ]; then 
echo "Error: Invalid time." 
echo "Usage: ./timer.sh "
exit 1
 fi
 while [ $min -g t 0 ] || [ $sec -g t 0 ]; do
 if [ $sec -e q 0 ]; then
 min=$((min - 1))
 sec=59 
else 
sec=$((sec - 1)) 
fi
if [ $min -e q 3 ]; then 
echo -ne "$min minutes remaining\r" 
e li f [ $min -e q 2 ]; then 
echo -ne "$min minutes remaining\r" 
e l if [ $min -e q 1 ]; then 
echo -ne "$min minute remaining\r" 
el i f [ $min -e q 0 ]; then
 echo -ne "$sec seconds remaining\r"
 fi
 sleep 1 
done 
echo -e "\n Time's up!"
Answer 2:
#!/bin/bash
 #initialize variables 
total_ size=0 
total_ files=0 
#get directory name from command line
 directory_ name=$1
 #change directory to given directory 
cd $directory_name
 #loop through all files in directory 
for file in * 
do 
#if file is a...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here