Compare log files and get latest


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare log files and get latest
# 1  
Old 07-22-2009
Bug Compare log files and get latest

I have a directory location where in some logs gets generated whenever some application build is triggered.
I need to send the generated log as an email to end user.
I will get files like abcyyyy_mm_dd_time.log and next file will have different time for same day.
Need to run a cron and take the latest file and email.
Need help how will I compare and get the latest file each time and send it across.
Any help asap will be highly appreciated ..
# 2  
Old 07-22-2009
Below will always give you the latest
Code:
ls -1t abc*.log | head -1

Rest is just little coding.
# 3  
Old 07-22-2009
Hi,

Below command can be used to take 5 recently modified or created files

Code:
  ls -1t dir/*|head -5

# 4  
Old 07-22-2009
Thanks for the Info but ls -lt | abc.log | head -1 will give the latest .
But say in last 10 minutes 3 logs got generated then I need to get those 3 and send too.
In a nutshell whatever gets created after I last sent the log file needs to be captured and sent...Smilie
# 5  
Old 07-22-2009
In such a case if abc.123.log is the last file I have sent
I will list down all the files with ls -lt | abc.*.log
and find the position of abc.123.log in the listing
and now head command with little alteration in -count can give me names of all the files.
Try it out... Smilie

btw it was 1(one) and not l(ell)
# 6  
Old 07-22-2009
Make file prevstamp = when you have done mail process. Find those files which are newer.
Code:
#!/bin/ksh
smail()
{
fn="$1"
/usr/lib/sendmail -t -i <<EOF
From: myemail
To: youremal
Subject: $fn

Here is file $fn
$(cat $fn)
EOF
}

##main##
[ ! -f prevstamp ] && touch -m 20010101120000 prevstamp
touch newstamp
find . -maxdepth 1  -name "*.log" -newer prevstamp | while read fname
do
        smail "$fname"
done
cp -fp newstamp prevstamp 2>/dev/null
rm -f newstamp 2>/dev/null

# 7  
Old 07-23-2009
Thanks for the script but why are you doing this here

20010101120000 prevstamp

Please explain...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read latest log files and perform database insert

Hi Experts, I have a situation where I need to write a shell script to continuously monitor a log directory with multiple log files and perform following: 1. Read the latest log file continuously and grep "Success" OR "Failure" 2. As it capture either Success or Failure, it has to perform a... (1 Reply)
Discussion started by: rish_max
1 Replies

2. Shell Programming and Scripting

Compare different String in Log Files

Hi Guys , sorry for my first post but a newbie here need some help on my simple scripts. I have some scripts below that count the job started and the job finished and is the job started and job finished equal ..then all job was successfully run and finished on that day. but sometime the was... (3 Replies)
Discussion started by: thermometer
3 Replies

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

4. UNIX for Advanced & Expert Users

Getting Latest files

Hai I wolud like to know how to get the latest files. ex: file_ssss_00 file_ssss_01 i need to get file_ssss_01 files only. (in Unix script) Please give some idea ... (2 Replies)
Discussion started by: raju4u
2 Replies

5. Shell Programming and Scripting

Require compare command to compare 4 files

I have four files, I need to compare these files together. As such i know "sdiff and comm" commands but these commands compare 2 files together. If I use sdiff command then i have to compare each file with other which will increase the codes. Please suggest if you know some commands whcih can... (6 Replies)
Discussion started by: nehashine
6 Replies

6. Shell Programming and Scripting

Compare 2 log files

Hello, I am new here, so first of all I want say hello to everyone. I am newbie on script but you may be able to help me on this : I am on solaris (ksh) I need to compare 2 files (one_trash.log / two_arch.log) On the first file I've got like 1000 entries files name Ex of one_trash.log... (15 Replies)
Discussion started by: Aswex
15 Replies

7. UNIX for Dummies Questions & Answers

To list only the very latest files

Hi, There are huge no of files in the directory. If i say ls -ltr it is taking too much time. i want to see only the files for Feb,2009. Please help. Thanks (3 Replies)
Discussion started by: venkatesht
3 Replies

8. Shell Programming and Scripting

to compare latest logfile with the current running time of the script

how can i compare the latest log file with the current time.. consider i am running a script "a.sh" at 09:00 ( function of the script a.sh is to update the database ) this script is going to create logfile if the script is sucess in case of failure it is not going to create logfile.. ... (0 Replies)
Discussion started by: mail2sant
0 Replies

9. Shell Programming and Scripting

Retain 3 latest files

Guys, Please can you tell me how to retain 3 latest files in a directory and get rid of the rest ? Thanks very much Regards, Ganesh (6 Replies)
Discussion started by: kamathg
6 Replies

10. Shell Programming and Scripting

Compare dates in a field and print the latest date row

Hi, I need a shell script which should find the latest date in the field of file and print that line only. For eg., I have a file /date.log Name Date Status IBM 06/06/07 close DELL 07/27/07 open DELL 06/07/07 open : : : From... (1 Reply)
Discussion started by: cvkishore
1 Replies
Login or Register to Ask a Question