Help me on a script

I have requirement as below:

I need to check the file has reached the server. If the file has reached it shall send a mail that file reached. For this i have used this script:

ssh username@server 'while [ ! -f path/file.txt ]
do
  sleep 60
done
echo " File has arrived.Please run the load  " | mailx -s "  File arrived " "<emailid> " '.

But i have an additional requirement. If the file has not reached the server for the day then it should come out of the loop and send me a mail that file has not reached server.I am not getting any idea how to end the loop.
Consider the cut off time as 11:30 pm.

  1. Know how long you want to try to run this for. You are waiting, so convert this to how many times it should try - maybe 120 - with a counter, and exit out of loop when the counter reaches that number.
  2. while in the loop, read the time and determine if the time is after your cut-off time.
1 Like

Hi joeyg,

Its that if i know the iteration number than i can break the loop.For example:If i scheduled my script at 6 pm and the cuttoff time is 11pm and sleep time is 60 secs,so 5 hrs it is going to check and run. considering a variable with the iteration number (here it will be 5*3600=18000 secs;18000/60=300) is 300.so it shall check till it has reached 300. I guess i can proceed in this way. Please give ur thought if u have any other way round.

You could try something like:

ssh username@server 'while [ ! -f path/file.txt ]
do
        if [ $(date +%H%M) -ge 2330 ]
        then    echo "File did not arrive today" |
                        mailx -s "File did not arrive" emailid
                exit 1
        fi
        sleep 60
done
echo " File has arrived.Please run the load  " | mailx -s "  File arrived " "<emailid> " '
2 Likes

Thanks Don. It worked!!!!
:b: