How to tail -f logfile. if log file is generate every 1 HR.?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to tail -f logfile. if log file is generate every 1 HR.?
# 1  
Old 07-09-2013
Hammer & Screwdriver How to tail -f logfile. if log file is generate every 1 HR.?

Hello,

How to tail -f logfile. if log file is gennerate every 1 HR.
I want it works automatically all the time. never changes it by manual.
Thank

Code:
ls -trl CybertonTransaction.*
-rw-r--r--   1 autobot   robot    617071 Jul  9 00:02 CybertonTransaction.20130709-00.log
-rw-r--r--   1 autobot   robot   20728938 Jul  9 01:59 CybertonTransaction.20130709-01.log
-rw-r--r--   1 autobot   robot   3808189 Jul  9 02:59 CybertonTransaction.20130709-02.log
-rw-r--r--   1 autobot   robot   4389986 Jul  9 03:59 CybertonTransaction.20130709-03.log
-rw-r--r--   1 autobot   robot   3801622 Jul  9 04:59 CybertonTransaction.20130709-04.log
-rw-r--r--   1 autobot   robot   25008198 Jul  9 05:59 CybertonTransaction.20130709-05.log
-rw-r--r--   1 autobot   robot   59425803 Jul  9 06:59 CybertonTransaction.20130709-06.log
-rw-r--r--   1 autobot   robot   100000019 Jul  9 07:48 CybertonTransaction.20130709-07.log.1
-rw-r--r--   1 autobot   robot   8122571 Jul  9 07:59 CybertonTransaction.20130709-07.log
-rw-r--r--   1 autobot   robot   30973114 Jul  9 08:59 CybertonTransaction.20130709-08.log
-rw-r--r--   1 autobot   robot   100000022 Jul  9 09:46 CybertonTransaction.20130709-09.log.1
-rw-r--r--   1 autobot   robot   17700625 Jul  9 09:59 CybertonTransaction.20130709-09.log
-rw-r--r--   1 autobot   robot   100000088 Jul  9 10:44 CybertonTransaction.20130709-10.log.1
-rw-r--r--   1 autobot   robot   25620434 Jul  9 10:59 CybertonTransaction.20130709-10.log
-rw-r--r--   1 autobot   robot   100000128 Jul  9 11:43 CybertonTransaction.20130709-11.log.1
-rw-r--r--   1 autobot   robot   41932541 Jul  9 11:59 CybertonTransaction.20130709-11.log
-rw-r--r--   1 autobot   robot   100000094 Jul  9 12:41 CybertonTransaction.20130709-12.log.1
-rw-r--r--   1 autobot   robot   42354186 Jul  9 12:59 CybertonTransaction.20130709-12.log
-rw-r--r--   1 autobot   robot   100000052 Jul  9 13:33 CybertonTransaction.20130709-13.log.1
-rw-r--r--   1 autobot   robot   27483687 Jul  9 13:59 CybertonTransaction.20130709-13.log
-rw-r--r--   1 autobot   robot   100000124 Jul  9 14:56 CybertonTransaction.20130709-14.log.1
-rw-r--r--   1 autobot   robot   7474128 Jul  9 14:59 CybertonTransaction.20130709-14.log
-rw-r--r--   1 autobot   robot   100000118 Jul  9 15:51 CybertonTransaction.20130709-15.log.1
-rw-r--r--   1 autobot   robot   14859881 Jul  9 15:59 CybertonTransaction.20130709-15.log
-rw-r--r--   1 autobot   robot   100000033 Jul  9 16:48 CybertonTransaction.20130709-16.log.1
-rw-r--r--   1 autobot   robot   27120181 Jul  9 16:59 CybertonTransaction.20130709-16.log
-rw-r--r--   1 autobot   robot   100000143 Jul  9 17:39 CybertonTransaction.20130709-17.log.1
-rw-r--r--   1 autobot   robot   44957555 Jul  9 17:59 CybertonTransaction.20130709-17.log
-rw-r--r--   1 autobot   robot   68461482 Jul  9 18:59 CybertonTransaction.20130709-18.log
-rw-r--r--   1 autobot   robot   68803772 Jul  9 19:59 CybertonTransaction.20130709-19.log
-rw-r--r--   1 autobot   robot   70048244 Jul  9 20:59 CybertonTransaction.20130709-20.log
-rw-r--r--   1 autobot   robot   48556923 Jul  9 21:59 CybertonTransaction.20130709-21.log
-rw-r--r--   1 autobot   robot   34699326 Jul  9 22:59 CybertonTransaction.20130709-22.log
-rw-r--r--   1 autobot   robot   64397410 Jul  9 23:59 CybertonTransaction.20130709-23.log

# 2  
Old 07-09-2013
1. Have a symbolic link point to the current hour log file.
2. Put a job in the hourly cron that will re-initialise the link to the current hour log file after every hour.

As an example, lets say CybertonTransaction.log is a symlink that points to current hour log file, say CybertonTransaction.20130709-22.log. After the time changes to 23:00 hrs, the cron job should re-link CybertonTransaction.log to CybertonTransaction.20130709-23.log.

And as a tip: If you're going to view the tail-ed output for hours together, use tail -F CybertonTransaction.log - tail with uppercase 'F' the symlink.
# 3  
Old 07-09-2013
i try shell script. but not work.
Code:
nowdate=$(date '+%Y%m%d-%H.log') 
fileName=`ls -tl /usr/home/TF/log/CybertonTransaction.$nowdate |head -1  |nawk  -F" " '{print $9}'`
echo $fileName
tail -f $fileName

# 4  
Old 07-09-2013
1) That's not what he suggested.
2) You don't need 'ls -l' here, if you just do ls -t you'll have far less work to do.

Script to run every hour:

Code:
LATEST="$(ls -t /usr/home/TF/log/ | head -n 1)"
ln -sf "${LATEST}" /usr/home/TF/log/latest.log

Then you can do
Code:
tail -F /usr/home/TF/log/latest.log

and it will do the right thing.
# 5  
Old 07-09-2013
I have around 22 logs , we are using tail to search the logs ,
I have to automate 1) if the log was updated on or before 24 hours from the current time 2) if there is a string matching the word ERROR it should send mail like it has ERROR or else it should exit without sending mail . Could any1 suggest me a way but definitely TAIL command is needed to extract the log ?
# 6  
Old 07-09-2013
Please ask your separate question in your own thread. Look in the forum you wish to post in and click the Image button.
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 07-09-2013
Quote:
Originally Posted by Corona688
1) That's not what he suggested.
2) You don't need 'ls -l' here, if you just do ls -t you'll have far less work to do.

Script to run every hour:

Code:
LATEST="$(ls -t /usr/home/TF/log/ | head -n 1)"
ln -sf "${LATEST}" /usr/home/TF/log/latest.log

Then you can do
Code:
tail -F /usr/home/TF/log/latest.log

and it will do the right thing.
it's not work.
after contrab run. can't tail new file automantic.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Alternative to tail -n -0 -F for monitoring live log file

Hello, I have been working on script which need to generate an alert based upon live logs. If string is found then an alert mail must triggered. tail -n -0 -F works fine to redirect the each latest line from live logs file to grep a pattern for matching but it seems to be not working on... (7 Replies)
Discussion started by: ketanraut
7 Replies

2. Shell Programming and Scripting

How to process only new line of tail -f command from live log file?

Hi, I want to read a live log file line by line and considering those line which are newly added to file Below code I am using, which read line but as soon as it read new line from log file its starts processing from very first line of file. tail -F /logs/COMMON-ERROR.log | while read... (11 Replies)
Discussion started by: ketanraut
11 Replies

3. Shell Programming and Scripting

How to tail -f multi logfile in 1 shell script.?

Hello, How to tail -f multi logfile from multi path in 1 shell script. File & Path /usr/home/localmode/mode110l/log/logic/number110/digit110_digit110m4_2013050210.txt /usr/home/localmode/mode103l/log/logic/number103/digit103_digit103m4_2013050210.txt... (4 Replies)
Discussion started by: ooilinlove
4 Replies

4. Shell Programming and Scripting

generate logfile in a shell script

Unix Gurus, I have a shell script which has few "echo" statements. I am trying to create a logfile where all the outputs of the echo statement sare stored. I will have to add this as the final step in the existing script so that everytime the script runs, a logfile is generated with all the... (1 Reply)
Discussion started by: shankar1dada
1 Replies

5. Shell Programming and Scripting

how to track a log file of one process and mail that logfile to a group?

Hi Friendz, I have 14 DB load scripts say 1,2,3....14. I want a script to call each script automatically, and after completion of every script, it needs to track the logfile and mail that log file to a group.and again it should run the next script in sequence 1,2,3...14 Please help me,need... (1 Reply)
Discussion started by: shirdi
1 Replies

6. Shell Programming and Scripting

Piping tail to awk to parse a log file

Hello all, I've got what I'm pretty sure is a simple problem, but I just can't seem to work past it. I'm trying to use awk to pretty up a log file, and calculate a percentage. The log file looks like this: # tail strtovrUsage 20090531-18:15:45 RSreq - 24, RSsuc - 24, RSrun - 78, RSerr -... (4 Replies)
Discussion started by: DeCoTwc
4 Replies

7. Shell Programming and Scripting

how to tail a log file..

Hi All.. I have a log file in which all the backup information is stored. Now i have written a script which get the last line in the backup log file.. ssh -l ora${sid} ${primaryhost} "tail -1 /oracle/$ORACLE_SID/sapbackup/back$ORACLE_SID.log" However i would like to tail the line last... (4 Replies)
Discussion started by: suri.tyson
4 Replies

8. Shell Programming and Scripting

Modify script to generate a log file

I've seen several examples of scripts in thise forum about having a script generate a log file. I have a script that is run from cron and that monitors a file system for a specfic filename(s) and then performs some actions on them. Normally I call this script from another script (which the one... (2 Replies)
Discussion started by: heprox
2 Replies

9. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: kriezo
2 Replies

10. Shell Programming and Scripting

tail -f a log file redirected into a new window?

Is this possible? I am attempting to display a new xterm window and tail -f the log file within that new window. I am currently working on a solaris 8 machine if that has any different meaning than the other platforms. As you can see, I am a newbie to this forum and to UNIX. Any help would be... (2 Replies)
Discussion started by: douknownam
2 Replies
Login or Register to Ask a Question