I'm trying to write a script that traps a exit signal and terminate. Instead of using the usual bash trap method, I would like to monitor a file creation every 10 seconds and cleanup some stuff before termination.
Here is what I have tried:
poll_time=10 // poll every 10 seconds
((term_time=$SECONDS+240)) // monitor until 4 min from current script time exec
while (( $SECONDS < $term_time)) do
if [[ -r $some_path/file.txt ]]; then
cleanup_function
exit
fi
sleep ${poll_time}
done
//if file doesnt exit continue with below code
//blah blah blah ....
Is there a better way to do this? will above lines of code work?
# blah
for comments.