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.

Answers were Sorted based on User's Feedback



Script S1 (which copies .dat files from one directory1 to another directory2) run continuously. W..

Answer / ganesh

Hi Vipul,

Script1 have to run continuously.. So,

Script1 should be

#!bin/sh

while true
do
cp directory1/*.dat directory2/
done

Is This Answer Correct ?    10 Yes 1 No

Script S1 (which copies .dat files from one directory1 to another directory2) run continuously. W..

Answer / 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

More Shell Script Interview Questions

What can scripts do?

0 Answers  


What are "c" and "b" permission fields of a file?

0 Answers  


In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc.

9 Answers   Amazon,


What does $@ mean in shell?

0 Answers  


How can you get the value of pi till a 100 decimal places?

0 Answers  






How do you know which shell I am using?

0 Answers  


Is bash an operating system?

0 Answers  


how to separate the even and odd number generated from one file to two separate file i.e. even numbers in file1.txt and odd numbers in file2.txt

4 Answers   Infosys,


Hi All, Is it possible to create one file name only space or space in file name in UNIX and we can able to run that on Unix?

2 Answers   Cap Gemini,


What is the best shell scripting language?

0 Answers  


Tell something about the super block in shell scripting?

0 Answers  


What are the three main forms of enabling debugging in a shell script?

6 Answers   ADC, Wipro,


Categories