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

Recommended Answers

All 5 Replies

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

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
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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.