Hi there,

I have a problem here that involves bash script since I was noob in that field. Recently, I have to monitor data involve in logs so I just run command tail –f for the monitoring. The logs was generate every hour so I need to quickly change my logs every time the new hour hits according to logs that been formatted in name-hour-date-month-year.log.

So here I think I would appreciated if someone can show me how to create a bash script that run the tail command or anything in similar and auto change the log file that need to be monitor when the new hour comes.

Please advice

10 Years
Discussion Span
Last Post by masijade

Wouldn't it be best to just run that as a cron job?

sory, i don't really get it. u mean i run the cron every hour to view it. Where did the cron will view it. I mean the screen. Can cron stop the view i was viewing and open the new file instead?


try this in a script:

while /usr/bin/true
xterm -e tail -f logfile
sleep 3600

this will open the tail in an xterm, wait exactly one hour (or close enough anyway)
and then open another (the logfile should have changed)

you probably will want to start this approximately one minute after a rotation has
occurred for the best effect.


sory masijade..
i'm running ssh secure client because the server was a remote access..
can i use xterm also?
Please advice..
Thank you.


as long as you have X11Forwarding set to yes on both the server and the client yes, you can
use xterm. For the server you must change sshd_config and restart. For the client you can
simply use -X (large x) on the command line.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.