Sponsored Content
Top Forums Shell Programming and Scripting How to tail real time file Generated every hour? Post 302632209 by methyl on Sunday 29th of April 2012 01:42:19 PM
Old 04-29-2012
Original post compared with suggested change from @spacebar:
Quote:
# Original post
while true; do newdate=$(date '+%Y%m%d') ; nowdate=$(date '+%Y%m%d-%H.log'); tail -f /usr/home/ABCD/atimo/log/$newdate/option/OP2/GatewayTransaction.$nowdate ;sleep 5 ; done ;

# Suggested change from @spacebar
while true; do newdate=`date '+%Y%m%d'`; nowdate=`date '+%Y%m%d-%H.log'`; tail -f /usr/home/ABCD/atimo/log/$newdate/option/OP2/GatewayTransaction.$nowdate; sleep 5; done;
The O/P stated that the original problem was "When creating a new file scripts not working".
Both of the above command sequences have this problem (the suggested change just makes an irrelevant change to the date command). They will both go wrong when the application starts a new file because the "tail -f" will lose context.

The big problem is because the script is using "tail -f".
There is no "quick and easy" way round this script design issue except to avoid "tail -f".

My usual approach to log file monitoring is to issue "wc -l" to find out the number of lines in the logfile, record that number in a workfile, then after the time interval calculate the new number of lines, calculate the difference and then issue "tail -n". This is a simplified view because we need to take account of the application starting a new file and will utililise the timestamp on our record file to detect the new file. The simplest approach to the "first time" condition is to do nothing except record the current state. This means that the logfile monitoring script needs to start running exactly one time increment earlier than the first report.


Ps. It always helps to know what Operating System and version you are running and what Shell you prefer.

Last edited by methyl; 04-29-2012 at 03:31 PM.. Reason: correct some ambiguity
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Real time log file redirect

Hi all, i would like to write the shell script program, it can monitor the access_log "real time" when the access_log writing the line contain "abcdef" the program will be "COPY" this line into a file named "abcdef.txt", do the same thing if the contain "123456" "COPY" it into a file named... (3 Replies)
Discussion started by: eric_wong_ch
3 Replies

2. UNIX for Dummies Questions & Answers

Live/real-time text-file updates in terminal

I want to have a terminal open and have something like a "repeating cat" command running in it for a certain text file (in particular /var/log/system.log). So my terminal will scan or cat the text file every so often or whenever the text file system.log gets written to by the system, it will... (1 Reply)
Discussion started by: guitarscn
1 Replies

3. Shell Programming and Scripting

How to tail -f real time file.

How to tail -f real time file. I want to tail file created last time. The server is gen new file Always. . An example file. -rw-r--r-- 1 shinnie tiituck 251M Oct 18 05:39 20111018_00.log -rw-r--r-- 1 shinnie tiituck 251M Oct 18 11:18 20111018_01.log -rw-r--r-- 1 shinnie tiituck... (3 Replies)
Discussion started by: ooilinlove
3 Replies

4. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

5. Shell Programming and Scripting

How to pick only the files which are generated in one hour?

Hello Masters, I need one help. I want to copy the files which are continuously generating on one server. But this would be on hourly basis. e.g. -rw-rw-r-- 1 akore akore 0 Feb 12 03:20 test1.log -rw-rw-r-- 1 akore akore 0 Feb 12 03:42 test2.log -rw-rw-r-- 1 akore akore 0 Feb 12 04:22... (2 Replies)
Discussion started by: akore83
2 Replies

6. Shell Programming and Scripting

How do i use tail & grep in real time here??

Hi I have a file which is updated very frequently. Where in i wanted to use tail -f command in the script and wanted to grep for a particular word. But the issue is when i use tail -f filename|grep "word" ... it will show me blank until the word is found in the real time. if it shows... (13 Replies)
Discussion started by: nikhil jain
13 Replies

7. Shell Programming and Scripting

Grep in a log file within a time range (hour)

Hi, im trying to write a grep script that returns me the last inputs added in the last hour in the log file. Literally i have nothing yet but: grep 'Line im looking for' LOGFILE.log | tail -1 this only gives me the last input, but no necessarily from the last hour. Help Please. (4 Replies)
Discussion started by: blacksteel1988
4 Replies

8. Shell Programming and Scripting

Archiving or removing few data from log file in real time

Hi, I have a log file that gets updated every second. Currently the size has grown to 20+ GB. I need to have a command/script, that will try to get the actual size of the file and will remove 50% of the data that are in the log file. I don't mind removing the data as the size has grown to huge... (8 Replies)
Discussion started by: Souvik Patra
8 Replies
TAIL(1) 								FSF								   TAIL(1)

NAME
tail - output the last part of files SYNOPSIS
tail [OPTION]... [FILE]... DESCRIPTION
Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too. --retry keep trying to open a file even if it is inaccessible when tail starts or if it becomes inaccessible later -- useful only with -f -c, --bytes=N output the last N bytes -f, --follow[={name|descriptor}] output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent -F same as --follow=name --retry -n, --lines=N output the last N lines, instead of the last 10 --max-unchanged-stats=N with --follow=name, reopen a FILE which has not changed size after N (default 5) iterations to see if it has been unlinked or renamed (this is the usual case of rotated log files) --pid=PID with -f, terminate after process ID, PID dies -q, --quiet, --silent never output headers giving file names -s, --sleep-interval=S with -f, sleep for approximately S seconds (default 1.0) between iterations. -v, --verbose always output headers giving file names --help display this help and exit --version output version information and exit If the first character of N (the number of bytes or lines) is a `+', print beginning with the Nth item from the start of each file, other- wise, print the last N items in the file. N may have a multiplier suffix: b for 512, k for 1024, m for 1048576 (1 Meg). With --follow (-f), tail defaults to following the file descriptor, which means that even if a tail'ed file is renamed, tail will continue to track its end. This default behavior is not desirable when you really want to track the actual name of the file, not the file descrip- tor (e.g., log rotation). Use --follow=name in that case. That causes tail to track the named file by reopening it periodically to see if it has been removed and recreated by some other program. AUTHOR
Written by Paul Rubin, David MacKenzie, Ian Lance Taylor, and Jim Meyering. REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>. COPYRIGHT
Copyright (C) 2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for tail is maintained as a Texinfo manual. If the info and tail programs are properly installed at your site, the command info tail should give you access to the complete manual. tail (coreutils) 4.5.3 February 2003 TAIL(1)
All times are GMT -4. The time now is 04:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy