Re: A script that will only check file if it has been modified since last check

From: Derk Gwen (derkgwen_at_HotPOP.com)
Date: 05/06/03

  • Next message: Colin McKinnon: "Re: A script that will only check file if it has been modified since last check"
    Date: Tue, 06 May 2003 21:29:17 -0000
    
    

    "LHradowy" <laura.hradowy@NOSPAM.mts.ca> wrote:
    # I have a script that greps the /var/adm/messages file for a pattern, write
    # it to a file. Then emails me a warning.
    #
    # The thing is I want to run this regularly, and the messages file is not
    # rotated regularly. How do I add this to the script that I only want it to
    # grep the file and email me if there is a new "pattern" not the same
    # "pattern" from an hour ago, or yesterday.

    One possibility is to capture the length of the file each time, and grep from
    there. A script might look like something like this untested code

    mv ~/lastLine ~/oldLastLine
            # Where previously read from.
    echo N=$(wc -l $ADMSG | awk '{print $1}') > ~/lastLine
            # Save the current file length.
    source ~/oldLastLine
            # Get the old file length into a variable
    tail -n +$N \
      | egrep 'currently marked as unusable|No more IP addresses on 192.168.2.0 network' \
    > $TEMP
            # Skip the first N lines, and grep for lines from there.
    rm ~/oldLastLine
            # Clean up

    When the log is rotated, also rest the lastLine file:

    echo N=0 >~/lastLine

    --
    Derk Gwen http://derkgwen.250free.com/html/index.html
    We found a loophole; they can't keep us out anymore.
    

  • Next message: Colin McKinnon: "Re: A script that will only check file if it has been modified since last check"

    Relevant Pages