How to tail -f real time file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to tail -f real time file.
# 1  
Old 10-19-2011
Computer 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.
Code:
-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 250M Oct 18 16:56 20111018_02.log
-rw-r--r--  1 shinnie tiituck 251M Oct 18 22:34 20111018_03.log
-rw-r--r--  1 shinnie tiituck  64M Oct 18 23:59 20111018_04.log
-rw-r--r--  1 shinnie tiituck 251M Oct 19 05:38 20111019_00.log
-rw-r--r--  1 shinnie tiituck 251M Oct 19 11:17 20111019_01.log
-rw-r--r--  1 shinnie tiituck 251M Oct 19 16:48 20111019_02.log
-rw-r--r--  1 shinnie tiituck 251M Oct 19 22:25 20111019_03.log
-rw-r--r--  1 shinnie tiituck  70M Oct 19 23:59 20111019_04.log

I can use this command it.
Code:
tail -f 201110??_??.log |grep "same key word"

# 2  
Old 10-19-2011
If you want to know the most recent file:
Code:
mLast=$(ls -1tr 20*.log | tail -1)
tail -f ${mLast} ...

# 3  
Old 10-19-2011
This might help you:

Code:
ls -ltr|head -1|awk '{print $9}'|tail -f

# 4  
Old 10-20-2011
Quote:
Originally Posted by madanlee
This might help you:

Code:
ls -ltr|head -1|awk '{print $9}'|tail -f

I am not sure why you would add the "-l" (long listing) which makes you use awk to remove the columns given with a long listing. You could remove the "-r" (reverse order) and "-l" (long listing) flags and use the "-w1" or "-1" (force 1 column width/1 file per line) for a better method would be:

Code:
ls -tw1|head -1|tail -f

or

Code:
ls -t1|head -1|tail -f


With an "ls" based command string you would have the added risk of finding directories as well as files. If someone were to create a directory after the last logfile was created and then that script/command ran you would get unexpected results.

Last edited by ddreggors; 10-20-2011 at 12:58 AM.. Reason: Additional Thoughts...
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to read a fast written log file at Real time speed?

Hello All, I am building a real time parser for a log file in my application. The log file is continuously written at a very fast pace and gets rolled over every 10 minutes. I have measured the speed and observed that around 1000 lines are written to it every second, each line about 30-40... (7 Replies)
Discussion started by: cool.aquarian
7 Replies

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

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

4. Shell Programming and Scripting

Copy real file from a shortcut preserving the time stamps and directory tree

I have directory with shorcuts of files. for example: gara@yn\short\name1 ( shortcut to gara@yn\FOLDER\OPT\GARA\1.jpg ) gara@yn\short\name2 ( shortcut to gara@yn\FOLDER\OPT\GARA\11.jpg ) gara@yn\short\name3 ( shortcut to gara@yn\MARA\URSA\2.jpg ) gara@yn\short\name4 ( shortcut to... (6 Replies)
Discussion started by: gogok_bg
6 Replies

5. Shell Programming and Scripting

How to tail real time file Generated every hour?

Hi Guys, I am developing a script to monitor log file Generated every hour. When creating a new file scripts not working. My Code . I want to monitor GatewayTransaction.yyyymmdd-hh.log while true; do newdate=$(date '+%Y%m%d') ; nowdate=$(date '+%Y%m%d-%H.log'); tail -f... (7 Replies)
Discussion started by: ooilinlove
7 Replies

6. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

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

8. 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
Login or Register to Ask a Question