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 to use arguments in a script?

577


Rewrite the command to print the sentence and convert the variable to plural: echo “i like $variable”.

563


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

1672


How do I run a script on mac?

568


I have 2 files and I want to print the records which are common to both.

688






What is the syntax of "nested if statement" in shell scripting?

627


What are scripts in psychology?

588


I want to monitor a continuously updating log file, what command can be used to most efficiently achieve this?

745


How to set an array in linux?

589


How do you find out What is your shell?

586


What is the use of break command?

583


Is powershell a bash?

586


What is the equivalent of a file shortcut that we have a window on a linux system?

598


What are the 3 standard streams in linux?

570


Which scripting language is best for automation?

528