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 is the crontab?

0 Answers  


what are command line arguments? what is the need of those?

1 Answers   Flipkart,


How would you print just the 25th line in a file using smallest shell script?

4 Answers  


What is shell scripting?

0 Answers  


How do I debug a shell script?

0 Answers  


How can I set the default rwx permission to all users on every file which is created in the current shell?

0 Answers  


what are special characters and explain how does text varies by the usage of single quotes,double quotes and back quotes?

1 Answers  


How to set an array in linux?

0 Answers  


What does egrep mean?

0 Answers  


There is a record with fields namely name,roll no.,salary,grade etc.Now,write a script to create a file with multiple records have same combination of fields but with unique roll numbers.The script should work for different names in the input file.

1 Answers   Wipro,


c program which accept one argument as a directory name and prints all the file name along with its inode number and total count of the file in directory

1 Answers  


how to search for vowels a,e,i,o,u appearing in the same sequence in a file

4 Answers   Amazon,


Categories