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.
Using tail to follow daily log file in Bash
logs;tail
The variable $CURRENTDATE isn't dynamic the way that you think. That variable gets expanded when the tail -F $CURRENTDATE command is evaluated to execute. You can see this if you run the ps command, AFTER it's executed. Notice in the output that it shows the value of current date rather than $CURRENTDATE.$ CURRENTDATE=$(date +%Y%M%d.log)$ tail -F $CURRENTDATE$ ps -eaf|grep tailsaml      1171 13564  0 22:13 pts/4    00:00:00 tail -F 20130517.logThis issue you're encountering is typically why most server daemons such as Apache, Nginx, or Jetty log all the current date into a file named, error.log, and then this file is rotated to another name, such as error_20130517.log afterwards.This allows you to monitor the error.log continuously using a command such as tail -F error.log.