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 are the zombie processes?

742


Is cmd a shell?

791


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

832


What shell is bin sh?

719


What language is bash written in?

770


Determine the output of the following command: [ -z “” ] && echo 0 || echo 1

765


What is path variable bash?

758


What is meant by dos operating system?

809


What is shell geeksforgeeks?

774


What command needs to be used to take the backup?

767


How to print the first array element?

794


one folder contains lot of students name but I want to fetch hello with every student name individually using shell script

740


What are types of shells?

768


What does $1 mean in bash?

823


Write down the syntax of "for " loop

818