search latest version of log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search latest version of log file
# 1  
Old 09-29-2008
search latest version of log file

Have checked the forums and couldnt locate help on this.

I want to grep a log file for a pattern using a script - I need to grep the latest log file and not sure how I am able to ensure I am greping the latest log file.

Here is sample of log files for yestersday and I effectively need to grep the file with version number 28 below - but obviously this version number could be different depending on time of day as it may have increased....

Any help?


-rw-r--r-- 1 user1 other 15925895 Sep 28 08:39 20080928_19.log
-rw-r--r-- 1 user1 other 15925032 Sep 28 08:54 20080928_20.log
-rw-r--r-- 1 user1 other 15928665 Sep 28 09:10 20080928_21.log
-rw-r--r-- 1 user1 other 15925819 Sep 28 09:25 20080928_22.log
-rw-r--r-- 1 user1 other 15927413 Sep 28 09:41 20080928_23.log
-rw-r--r-- 1 user1 other 15925002 Sep 28 09:56 20080928_24.log
-rw-r--r-- 1 user1 other 15927538 Sep 28 10:12 20080928_25.log
-rw-r--r-- 1 user1 other 15925392 Sep 28 10:27 20080928_26.log
-rw-r--r-- 1 user1 other 994628 Sep 28 10:50 20080928_27.log
-rw-r--r-- 1 user1 other 183662 Sep 28 23:59 20080928_28.log
# 2  
Old 09-29-2008
Following can be used :

Code:
ll -ltr *.log| tail -1

# 3  
Old 09-29-2008
Quote:
Originally Posted by nua7
Following can be used :

Code:
ll -ltr *.log| tail -1


ll -ltr *.log| tail -1
bash: ll: command not found


I am on Solaris 10 - is ll the right command?
# 4  
Old 09-29-2008
check if ls-l command works for you..
# 5  
Old 09-29-2008
yes ls -l is fine and ls -ltr is fine

However the return of ls -ltr | tail -1 is:
-rw-r--r-- 1 user1 other 183662 Sep 28 23:59 20080928_28.log

I still need to be able to just grep the file name found above as part of a script.
ie. I need to be able to grep pattern <latest_file>
# 6  
Old 09-29-2008
Many ways to do this...one way...check this out...

Code:
ls -ltr | tail -1 | cut -d " " -f10

# 7  
Old 09-29-2008
Code:
grep pattern $(ls -lrt | awk '{ file=$NF } END { print file }')

The value of $(command ...) is the output of command ...

If your shell doesn't support the $(...) syntax you will have to use `...` instead. Those are backticks (grave accents, ASCII 96) not regular straight quotes.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Fetch latest version form a file?

Hi, I have a file where versions will be updated, i need to get latest/last updated version from that file. Could you please help? File looks like below - <versions> <version>R20180417.006</version> <version>R20180421.007</version> <version>R20180421.008</version> ... (5 Replies)
Discussion started by: schandra128
5 Replies

2. Shell Programming and Scripting

Search for latest Timestamp in file

Hi, I have a file which generate Timestamp in this format :- 20121012162354 20121114191610 20121210232808 20121216220002 20130106220002 20130127220001 20130203220001 20121012162354 20121114191610 20121210232808 20121216220002 20130106220002 20130127220001 20130203220001 (2 Replies)
Discussion started by: netdbaind
2 Replies

3. Shell Programming and Scripting

Help with finding the latest modified version of a file within directories

I am trying to look into multiple directories and pluck out the latest version of a specific file, regardless of where it sits within the directory structure. Ex: The file is a .xls file and could have a depth within the directory of anywhere from 1-5 Working directory - Folder1... (6 Replies)
Discussion started by: co21ss
6 Replies

4. AIX

Latest firmware version for P770

Dears i have a power7 P770 working in AIX 5.3 TL 11 with frimware AM730_066 is the AM730_066 frimware the latest one or not ? (6 Replies)
Discussion started by: thecobra151
6 Replies

5. Shell Programming and Scripting

Perl's buffered I/O is causing me to miss latest log file entries in log colorizer. How to fix?

I've been finding myself using a log file colorizer written in perl to reformat and colorize the output from many different programs. Mainly, however, I use it to make the output from "tail -f" commands more readable. The base perl script I use is based on "colorlogs.pl" available from the... (1 Reply)
Discussion started by: rcsteiner
1 Replies

6. Shell Programming and Scripting

search for latest file

Hi, In need to write a bash script which will be run periodically to check the files in a target directory. This receives files on an ad hoc basis and the script need to compare the time stamp of the latest file received with system time and write a message to the server log file if the time... (2 Replies)
Discussion started by: mark_s_g
2 Replies

7. BSD

latest version of bsd

Any body there ? What is latest BSD version ? (4 Replies)
Discussion started by: chilaka
4 Replies

8. Shell Programming and Scripting

Latest version of a file across the servers ..

:o How do I confirm that the script on one server is latest compare to other servers? Is there any script which can tell me the latest version of a file across the servers? Thanks, (2 Replies)
Discussion started by: Sandy
2 Replies

9. UNIX for Dummies Questions & Answers

What is the latest version of Unix?

I want to buy it (2 Replies)
Discussion started by: LANSTARR.COM
2 Replies

10. UNIX for Dummies Questions & Answers

Downloading vs buying latest version of os

I am currently taking a Unix programming class in school, I want ot know which is more efficient and quicker, downloading the os or buying the os (4 Replies)
Discussion started by: lavonte
4 Replies
Login or Register to Ask a Question