Script S1 (which copies .dat files from one directory1 to
another directory2) run continuously.
Write Script S2 which kills S1 first, compresses all .dat
files in directory1 and directory2 successfully, re-run
Script S1 and stops self i.e. S2.
Answer Posted / vipul dalwala
script1.sh
#!/bin/bash
cp directory1/*.dat directory2/
script2.sh
#!/bin/bash
PSIDODSCRIPT1=`ps -a | awk '/script1\.sh/ && !/awk/ {print
$1}'
SELFID=$$
kill -9 ${PSIDODSCRIPT1}
find directory1 -name '*.dat' -exec gzip {} \;
if [ $? -eq 0 ]
then
find directory2 -name '*.dat' -exec gzip {} \;
if [ $? -eq 0 ]
then
sh script1.sh
kill -9 ${SELFID}
else
exit
fi
else
exit
fi
| Is This Answer Correct ? | 7 Yes | 3 No |
Post New Answer View All Answers
Explain about sourcing commands?
How will you connect to a database server from linux?
Why is shell scripting important?
What is shell geeksforgeeks?
When should shell programming/scripting not be used?
What is the equivalent of a file shortcut that we have a window on a linux system?
What is a shell? · Types of shell · what is shell scripting?
What is shell scripting?
How do I run a shell script in powershell?
What is ms powershell?
What is bash shell command?
How to redirect both standard output and standard error to the same location?
How can we find the process name from its process id?
Explain about echo command?
What is an sh file?