search for a file, if not found sleep and repeat it for 3 hrs

Hi,

Can someone help me with this script ....

I need a ksh script, which will search for a specific file in a directory, if file not found sleep for 10 mins and search again, if still not found sleep again for 10 mins and so on .... it should search for that file for 3 hours and if that file is still not found, then it should send a e-mail.

Appriciate your help with this ...

Thanks,
Sant

This won't be a complete answer, as ksh really isn't my thing; however, I would base a quick and dirty script of this kind you describe on the fact that there are 18 10-minute periods in 3 hours. So, something like this might be a reasonable framework:

integer n=0
while ((n <= 18));
do
     if [[ -e filename ]]
          then
               integer n=19
          else
               if [[ n = 18 ]]
                    Send your mail with whatever command you need....
               else
                    sleep 600
               fi
     fi
n++
done

Anyway, that's the idea... it'll require lots of work, and I would be stunned if it ran without significant alteration. Some of it probably isn't even valid ksh. Hopefully it gives you a starting point, though.

>Can someone help me with this script ....

Where is it?

Here is the script i tried ...

#! /usr/bin/ksh

File="abc.txt"

if [ -f $DIR/$File ]
then
echo "File Found"
break
else
i = 0
echo "File Not Found! Wait for 10 mins and try searching again!"
sleep 10m
i = i + 10
if [i &gt; 120]
then
echo "Alert!! File not found for 2 hrs!!" | mailx -s "File not found" abc@abc.com
break
fi
fi

By courtesy of era:
a self-scheduling at job is also an option:.

#!/bin/sh
: your code here # you would need a counter to end (see above thread of treesloth) 
                      # and mail after 3 hours of unsuccessfull attempts...etc..

echo "$0" "$@" | at now + 10 minutes

Thanks for all ur help ...

here goes the final script ...

while (( $i <= 60 ))
do
  if [ -f $File ]
  then
      echo "File Found"
      break
  else
      sleep 10
      i=`expr $i + 10`
      if [ $i -gt 60 ]
      then
          echo "ALERT!!" | mailx -s "ALERT!!" ${ID}
      else
          sleep 1
      fi    
  fi
done