Find the answer to your Linux question:
Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By digitalamish
Hi im struggling to get a script sample, i need the script to do the following: It needs to search a log file then if the word searched is found ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2011
    Posts
    4

    Unhappy Script To search a log and mail if word is not found


    Hi im struggling to get a script sample, i need the script to do the following:

    It needs to search a log file
    then if the word searched is found it must do nothing
    otherwise it needs to mail to a address if it is not found

    Please guys this is Urgent.

    I really need help on this

    thanx in advance hope if this is solved that it will help alot of poeple

    Kind Regards to all you linux fans

  2. #2
    Just Joined!
    Join Date
    Jan 2008
    Posts
    21
    I can't help you with the script, but I can tell you that emailing can be problematic. Check out a service called SendGrid, which is free if you send < 100 messages per day. I use blat to shoot the messages to them under Windows; you'll need a similar command (sorry, have no idea what) to do the same.

    Hope this helps!

    I.

  3. #3
    Just Joined!
    Join Date
    Mar 2011
    Posts
    2
    in sh or bash using mail for mailer

    Code:
    x=`grep -c word logfilename
    if [ x -eq 0 ]
    then
    echo "email text" | mail -s subject receiver@domain
    fi
    leewagner likes this.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Jun 2011
    Posts
    4
    Thanks Will try this thanx for the reply

  6. #5
    Just Joined!
    Join Date
    Mar 2011
    Posts
    2
    There is a missing backtick on the first line. Should be:

    Code:
    x=`grep -c word logfilename`

  7. #6
    Just Joined!
    Join Date
    Jun 2011
    Posts
    4

    Thumbs up Thank you very much "digitalamish" & "ibexslam"

    Hi I ended up figuring something else out i'll post it here and hope it helps alot of you guys

    Thanx for the mail thread needed that pipe option

    #!/bin/bash


    grep "grep value" /destination/file.log -c > name.txt

    new=`cat name.txt`
    old=`cat name.old.txt`
    echo "$new"
    echo "$old"


    if [ $old -lt $new ]
    then
    echo continue
    else
    echo error

    echo "body" | mailx -s "subject" user@domain user@domain.com

    fi

    mv -f pop.txt pop.old.txt

Posting Permissions

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