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 does path stand for?

0 Answers  


I want to create a directory such that anyone in the group can create a file and access any person's file in it but none should be able to delete a file other than the one created by himself.

0 Answers  


c program to implement unix/linux command to block the signal ctrl-c and ctrl-\ signal during the execution ls -l|wc -l

0 Answers  


Why are shell scripts used?

0 Answers  


What is the use of .sh file?

0 Answers  






What can you do with powershell?

0 Answers  


How can you find out how long the system has been running?

0 Answers  


Explain about shebang?

0 Answers  


What is the best shell scripting language?

0 Answers  


How do I run a script from command prompt?

0 Answers  


What is a boot block?

0 Answers  


c program which behaves like a shell(command interpreter). it has its own prompt say "NewShell$".any normal shell command is executed from your shell by starting a child process to execute a system program corrosponding to the command

0 Answers  


Categories