How to compare below output?

I'm very new to shell scripting, below is my output in status.txt

CM                                     TARGET     ACTUAL 
---------------------------------- ---------- ---------- 
Conflict Resolution Manager                 1          1 
Internal Manager                            1          1 
Standard Manager                           18         18 
Workflow Agent Listener Service             1          1 
Workflow Mailer Service                     1          1 
Output Post Processor                       1          1

My requirement is to compare target and actual.
If any difference should send mail "$CM down" I know we can use awk and sed utilities but something else
like (if,then,else) also needs to be used.
That's where i'm not able to create logic.
Please help me in this.

awk 'NR>2' status.txt | while read line; do
  if [ -n "`echo $line | awk '$NF!=$(NF-1)'`" ]; then
    mail -s "$line" your@mail.address < /dev/null
  fi
done

Hi Bartus11,

Not getting desired output.
I'm executing the script as below.
---------------------------------

#!/bin/bash

awk 'NR>2' status.txt | while read line; do
  if [ -n "`echo $line | awk '$NF!=$(NF-1)'`" ]; then
    mail -s "$line" xyz@pqr.corp.com < /dev/null
  fi
done

-------------------------------
I should get message like
$CM is down

e.g Output Post Processor is down

Try:

awk 'NR>2' status.txt | while read line; do
  if [ -n "`echo $line | awk '$NF!=$(NF-1)'`" ]; then
    MSG="`echo $line | awk '{NF-=2}1'` is down"
    mail -s "'$MSG'" xyz@pqr.corp.com < /dev/null
  fi
done
1 Like
awk '
        NR > 2 {
                if ( $NF != $(NF - 1) )
                {
                        NF -= 2
                        print $0 " is down" > "mail_body"
                }
        }
' status.txt

[ -s mail_body ] && mailx -s "Alert" xyz@pqr.corp.com < mail_body
1 Like

Try also

$ awk 'NR > 2 && $(NF-1) != $NF {$NF=$(NF-1)=""; print $0 " is down" | "mail -s Status xyz@pqr.corp.com"} ' file
1 Like