Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to read the latest log file

Status
Not open for further replies.
Oct 9, 2003
174
US
Hey guys

As part of a script, I am trying to output the last line of a log file from the previous nights backup. The problem that I have is when the job fails there is two or sometimes three log files in the directory. I want the script to always read the latest log file. This wasn't a problem with Tru64 UNIX becuase it always read the latest file first. But in Solaris it looks like it reads the earlier file first even though im using the korn shell in both OS's.

I do a:
tail -1 *oraexp*.log

On a directory like this:
-rw-r--r-- 1 oracle oinstall 310506 Feb 2 23:47 testcp_oraexp_2004020222.log
-rw-r--r-- 1 oracle oinstall 310524 Feb 3 09:00 testcp_oraexp_2004020323.log

I'm looking to get this, Which I use as a testing string for other parts of the script.:
Export terminated successfully without warnings.

does anyone know how I could have the tail -1 command always look at the latest log file?

Thanks in advance.



 
Try this:

tail -1 `ls -t *oraexp* | head -1`

Jean Pierre.
 
Oops, I mean't thanks.

One last thing. This is probably very simple for you guys but I'm having a problem declaring that command as a variable.

TEST=tail -1 `ls -t $HOME/testcp/*oraexp*.log | head -1`

Gives:

-1: not found

How can i fix this.
 

last_file=`ls -t $HOME/testcp/*oraexp*.log | head -1`
TEST=`tail -1 $last_file`

or

TEST=`ls -t $HOME/testcp/*oraexp*.log | head -1 | xargs tail -1`

or

tail -1 `ls -t $HOME/testcp/*oraexp*.log | head -1` | read TEST


Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top