If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > previous day's files

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-25-06, 18:36
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
previous day's files

I have a directory '/opt/storage/logdir' where a bunch of logs files
are written everyday(.log files)
How do I write a script that runs everyday and looks for the previous day's log files, searches for the
word 'HALTED' in yesterday's files and then emails the contents of that particular file
to a specified email Id ?
For example,

-rw-r----- 1 user group 23456334 Apr 26 15:01 4343.log
-rw-r----- 1 user group 896765 May 24 15:59 3221.log
-rw-r----- 1 user group 22151186 May 25 16:59 4632.log

If this script runs on May 25th, it needs to search for the word 'HALTED' in 3221.log
and if found, email the contents of 3221.log with the subject 'HALTED found in 3221.log' ?
Reply With Quote
  #2 (permalink)  
Old 05-26-06, 07:39
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
look at the find command e.g.
find /opt/storage/logdir -mtime -3 -mtime +1

And mailx e.g.
cat logfile | mailx -s "subject" recipient@host

But, do you really want to email such a big file and can your mailbox handle it
It seems the log file can be more than 20 MB big
Reply With Quote
  #3 (permalink)  
Old 05-26-06, 09:27
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
I looked at it again. On second thoughts, if it can just print the subsequent lines (after the HALTED) until it finds a whole blank line, that is fine(rather than the whole file)
For example :if the contents of the log file are --------

overcome:work Action:"Halted" Code :0 aaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccc c
ddddddddddddddddd

join:hotel Action:"Continue" Code:1 ffffffffffffffffffffffffffffffff

entry:single Action:"Halted" Code:3 bbbbbbbbbbbbbbbbbbbbb
ssssssssssssssssssssssssssssssssssssssssssssssssss sssssssss

In the above case, it would just email ------------

overcome:work Action:"Halted" Code :0 aaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccc c
ddddddddddddddddd

entry:single Action:"Halted" Code:3 bbbbbbbbbbbbbbbbbbbbb
ssssssssssssssssssssssssssssssssssssssssssssssssss sssssssss

Can you help me with a script to do the above ? (still trying to get my hands around)

Thanks
Reply With Quote
  #4 (permalink)  
Old 05-26-06, 13:28
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
Never mind...I got it...

find $HOME/logdir -mtime -1 | xargs grep 'HALTED' > $outfile

And I emailed the outfile to myself

Thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On