Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    143

    Unanswered: 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' ?

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    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

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

  4. #4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •