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
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.
Command we tried using to grep ERROR from lastest 1 log files from 5 logs files available in that particular directory is:
grep ERROR $(ls -lrt | awk '{ file=$NF } END { print file }')
grep: can't open DistributeImageFilesToTarget_10_dataLocations_PhillipinesDataLocations.xml.log
if i give ls -lrt for all the files in that diretory