How to compare below output?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to compare below output?
# 1  
Old 05-18-2013
How to compare below output?

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

Code:
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.

Last edited by Scrutinizer; 05-18-2013 at 08:10 AM.. Reason: code tags
# 2  
Old 05-18-2013
Code:
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

# 3  
Old 05-18-2013
Hi Bartus11,

Not getting desired output.
I'm executing the script as below.
---------------------------------
Code:
#!/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

Last edited by Franklin52; 05-18-2013 at 10:03 AM.. Reason: Please use code tags
# 4  
Old 05-18-2013
Try:
Code:
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

This User Gave Thanks to bartus11 For This Post:
# 5  
Old 05-18-2013
Code:
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

This User Gave Thanks to Yoda For This Post:
# 6  
Old 05-18-2013
Try also
Code:
$ awk 'NR > 2 && $(NF-1) != $NF {$NF=$(NF-1)=""; print $0 " is down" | "mail -s Status xyz@pqr.corp.com"} ' file

This User Gave Thanks to RudiC For This Post:
# 7  
Old 05-20-2013
it worked . thanks

Quote:
Originally Posted by bartus11
Try:
Code:
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

To compare two files,Output into a new file

Hi Please help me to compare two files and output into a new file file1.txt 15114933 |4001 15291649 |933502 15764675 |4316 15764678 |4316 15761974 |282501 15673104 |933505 15673577 |933505 15673098 |933505 15673096 |933505 15673092 |933505 15760705 ... (13 Replies)
Discussion started by: Ankita Talukdar
13 Replies

2. UNIX for Dummies Questions & Answers

Compare two files and output to new file

Hi, Please help How to compare two files- Any mismatches 2nd and 3rd column's values corresponding to 1st column. file1 15294024|Not Allowed|null 15291398|Not Allowed|null 15303292|Dropship (standard)|N 15303291|Dropship (standard)|N 15275561|Store Only|Y 15275560|Store Only|Y... (2 Replies)
Discussion started by: Ankita Talukdar
2 Replies

3. Shell Programming and Scripting

Compare output from two commands

Hello folks, I would like ask for a help in one script I'm currently working on. Main goal is to compare size of file available on remote site and file already downloaded (check if downloaded file is complete and non corrupted). # Check if files were downloaded correctly for FILES in... (6 Replies)
Discussion started by: brusell
6 Replies

4. Shell Programming and Scripting

Compare two files and output in another file

I have two files ' 1st one ALIC-000352-B ALIC-000916-O DDS-STNGD FDH-PPO1-001 PFG-30601-001 2nd one 'ALIC-000352-B' 'ALIC-000916-O' 'DDS-STNGD' 'FDH-PPO1-001' (4 Replies)
Discussion started by: Pratik4891
4 Replies

5. Shell Programming and Scripting

Compare two files in different formats and get output

File A: DATAFILE TABLESPACE ------------------------- ------------------------- /dev/rprod_0032_011 D_EEM /dev/rprod_0032_012 D_ESO_REF ... (1 Reply)
Discussion started by: Daniel Gate
1 Replies

6. Shell Programming and Scripting

Compare two files and get output

Hi, I have two files, file1 and file2 and I need to compare them by line (exact match, order of the lines is not important) and get output with lines from file2 that are not found in file1 (not other way around). How do I do that? With grep or otherwise.. Thankyou (2 Replies)
Discussion started by: orp56
2 Replies

7. Shell Programming and Scripting

compare 2 files > output new to third

Hi, I have a question of comparing to files and output the result third file where file1 is the mainfile containing processed dir data and 2nd file grepīs dirīs data again (could be newer dirs comparing file1<file2) now i wanna make shure that output in file3 only contains newer dirs hx... (1 Reply)
Discussion started by: needle
1 Replies

8. Shell Programming and Scripting

Compare string output to int value?

Hi, i'd like to implmeent emergency shutdown script in case our AC dies and the temperature rises too high. I can get core temperatures with: sensors | grep Core | cut -c15-16 Result is: 23 18 18 13 21 18 15 17 How can I check if any of the cores is above eg. 80 (that's C of... (2 Replies)
Discussion started by: zapp0
2 Replies

9. UNIX for Dummies Questions & Answers

Compare Files and Output Difference

I have to compare two files for any differences, then output the lab and question number for any differences. This is what I currently have: diff lab2.txt lab2answer.txt > lab2compare.txt Though the output doesn't have to be sent to a .txt (or any sort of log), I found that easier, at least... (2 Replies)
Discussion started by: Joesgrrrl
2 Replies

10. Shell Programming and Scripting

Compare output from awk to a value

I need to write a shell script which checks the CPU utilization is above 90% for a particular process. So far I have done this prstat 0 1 | grep weblogic | awk '{print $9}' This give an output like this 0.1% 0.0% 0.0% 0.0% 0.0% Now I need to assign this to an array and check... (4 Replies)
Discussion started by: venishjoe
4 Replies
Login or Register to Ask a Question