I have a task to use a bash script to monitor a couple of log files named with the current day, eg. YYYY-MM-DD.log.
(1) I used
tail -f to follow the file but unable to deal file rotation.
Even if using
tail -F $FILENAME, I can only follow the log for 24 hours max and need to restart again.
What I wish to accomplish is to have something like
tail -F $CURRENTDATE, so I can leave it running forever and every midnight It will switch to follow the new log file named with current date.
But it seems the variable
$CURRENTDATE is not dynamic. Is there another way to do this without
crontab'ing the script every 24 hours? Maybe set a symbolic file or something?
(2) Meanwhile, if
tail -f is used, what signal will it return if the file it follows is missing or changes its name? How can I trap the exceptions during execution.