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

What happens when you type ls?

566


How do I open the shell prompt?

576


What is a program shell?

571


What is sed in shell script?

571


Where are cowrie shells found?

580






madhar chod unix ke 10 commands dhang se likh nahi sakta hai

2976


Which shell is the best?

576


What are the different communication commands available in the shell?

519


What are the 3 standard streams in linux?

573


How to calculate the number of passed arguments?

556


What is a shell made of?

558


Explain about sourcing commands?

640


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

1723


Write a command sequence to find the count of each word?

542


What does egrep mean?

575