Results 1 to 3 of 3

Thread: Shell Script

  1. #1
    Join Date
    Oct 2008
    Posts
    82

    Cool Unanswered: Shell Script

    Hi ,

    I am writing a shell script to find the failures ..

    I am getting below update in to the variable

    var=`grep -i "failed" $FILE`

    output : total failed :0
    total failed :0
    total failed :0
    total failed : 0

    Here I need the logic like - I need a mail if it results other than 0 in any line..

    Can anyone please help me on this ..

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Code:
    #datafile
    abc
    failed
    def
    Code:
    grep failed datafile
    echo $?
    grep yes datafile
    echo $?
    $? is set to 0 if the command is successful or 1 if unsuccessful.

  3. #3
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Quote Originally Posted by rameshj6 View Post
    Hi ,
    . . . E t c . . .
    Here I need the logic like - I need a mail if it results other than 0 in any line..
    ..
    Try something like this:
    Code:
    var=`awk -F'[ :]' '/failed/{e+=$NF}END{print e}' $FILE`
    if [ var -ne 0 ]
    then
      echo "!Errors in file $FILE"|mail -s'Process failed.' mymail@mydomain.com
    fi
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

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