[Solved] Help with shell Script ,wait for some files for some time??

Hi All,

I have the requirement that ,i have to write a shell script that job has to wait for a 7 touch files created by another application for 4 hours, if i get all 7 touch files ,i have to send a mail that i jobs are completed, if if it is waiting for more than 4 hours i have to send a mail that job is running for a longer time.
i know the names of all the touch files, how can i achieve this in sell script,

please anyone could help me on this, please try to share your slutions and opinions , as i am new to this shell scripting ..

thanks in Advance!!!
Pradeep

There is a built-in SECONDS variable you can use... When it becomes greater than 14400, 4 hours will have passed.

#!/bin/sh

T=$((60*60*4))

# while file1 doesn't exist, or file2 doesn't exist, or file3 doesn't exist, ...
while [ ! -e file1 ] || [ ! -e file2 ] || [ ! -e file3 ] || 
        [ ! -e file4 ] || [ ! -e file5 ] || [ ! -e file6 ] ||
        [ ! -e file7 ]
do
        # wait another minute for files to appear
        sleep 60
        # Break loop if we've waited longer than 4 hours.
        [ "$SECONDS" -gt $T ] && break
done

# Quit if 4 hours exceeded
if [ "$SECONDS" -gt $T ]
then
        echo "timed out"
else
        echo "got files"
fi | mailx -s "subject" person@addr
1 Like

Thank u Corona688 for the perfect solution and quick response ,

its working fine for me...

thanks!!!!
pradeep

1 Like