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


Please Help Members By Posting Answers For Below Questions

How do I edit a .sh file?

607


Is it possible to substitute "ls" command in the place of "echo" command?

605


What are the default permissions of a file when it is created?

480


What can scripts do?

654


What is the difference between bash and shell?

633






How are shells born?

540


Print the 10th line without using tail and head command.

1657


what is tickets $ what low,medium,high priorite pls define time also

1709


What is an sh file?

547


How do I run a script on mac?

561


What is echo in shell?

628


How do I run a .sh file on mac?

660


How will you copy a file from one machine to other?

538


How does path variable work?

537


How does ls command work?

573