954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Bash tail monitor log file

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
TQ.
:(

kriezo
Newbie Poster
3 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

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

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 
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?

kriezo
Newbie Poster
3 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

try this in a script:

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

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.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

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

kriezo
Newbie Poster
3 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

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.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You