I am creating a script that should wait until a certain file (e.g. stop.dat
) appears or after certain time (e.g. 500 Seconds) has passed.
I know how to wait until the file appears:
while [ ! -f ./stop.dat ]; do
sleep 30
done
How can I add the other statement in my while loop?
If you want to do it this way, then you can do something like:
nap=30; slept=0
while [ ! -f ./stop.dat ] && ((slept<500)); do
sleep $nap;
slept=$((slept+nap))
done
Using inotifywait instead of polling would be a more proper way of doing it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With