Help with sleep function

Hey everyone, just entering the linux world, I need some help with a shell script i'm trying to write, the purpose is to check every 10 minutes what was the last time a certain file was modified, and if there is a connection to the server at this moment send an email with the date of the modification, if there is no connection, wait till there is - send the mail and wait another 10 minutes.

This is what I got:

Forever=1

while [ ${Forever} ] ; do
sleep 600
ping 192.168.1.254 -c 1
while [ $? -ne 0 ] ; do
    ping 192.168.1.254 -c 1
done
echo "Log Mail" | mail -s "file last modified on $(stat -c %x pf.cf)"
done

it seems that the mail is sent 10 minutes after the connection was established (which is not what im trying to achieve)
any help and suggestions would be much appreciated!

If you start by waiting 10 minutes, it is normal that the mail get sent after this duration :wink:

while :
do
ping 192.168.1.254 -c 1
while [ $? -ne 0 ] ; do
ping 192.168.1.254 -c 1
done
echo "Log Mail" | mail -s "file last modified on $(stat -c %x pf.cf)"
sleep 600
done

you can use ":" instead of all your $Forever stuff
: stand for true or /bin/true (depends your OS)

1 Like

I like linux
Thanks for the help, it actually makes sense and wasn't that difficult.