Operating System - HP-UX
1833780 Members
2637 Online
110063 Solutions
New Discussion

Re: comparing columns in the text file

 
pareshan
Regular Advisor

comparing columns in the text file

I have written down a script which gives following output which I run everyday and everytime it runs and it supposed to give the same output. I have put the data in excel spreadsheet with which I manually compare the output of the script everyday which takes lots of time because this output is not even 10 percent of actual output just I put 10 lines to give an example.

here is the output of the script

server1 10/20/2006 10/19/2011 permanent number of cpus: 16
server2 04/01/2009 04/30/2009 temporary number of cpus: 16
server3 03/30/2006 03/29/2011 permanent number of cpus: 16
server4 05/31/2008 05/30/2013 permanent number of cpus: 56
server5 04/01/2009 04/30/2009 temporary number of cpus: 32
server6 04/01/2009 04/30/2009 temporary number of cpus: 32
server7 03/30/2006 03/29/2011 permanent number of cpus: 48
server8 08/30/2006 08/29/2011 permanent number of cpus: 64
server9 10/31/1999 10/30/2012 permanent number of cpus: 16
server10 08/31/2006 08/30/2011 permanent number of cpus: 40

I am trying to find a way to compare that original data with the output script produce everytime it runs using script so that i wont spend my some hours daily doing that but I coulnt figure out how to do it.

Could you guys help me how can I do this please
Any help will be appreciated
thanks
4 REPLIES 4
pareshan
Regular Advisor

Re: comparing columns in the text file

Sorry forget to add main part above,

and if something is changed should email the changes to the group so that they know what things are changed.
for example number of cpus changed on the server1 it should send alter to pidit@gmail.com saying number of cpus (or the field changed) change is server 1
:)
James R. Ferguson
Acclaimed Contributor

Re: comparing columns in the text file

Hi:

YOu could do something like this:

#!/usr/bin/sh
typeset MYBASE=/var/tmp/mybase
typeset NEWBASE=/var/tmp/newbase
typeset MYDIFF=/var/tmp/mydiff
diff ${MYBASE} ${NEWBASE} > ${MYDIFF}
[ -s "${MYDIFF}" && mailx root -s "Files differ!" < ${MYDIFF}
mv ${NEWBASE} ${MYBASE}
...

If the files differ, you will get an email of the differences; otherwise not.

Regards!

...JRF...
OldSchool
Honored Contributor

Re: comparing columns in the text file

the "diff" method illustrated will work if nothing (including dates shown in example) vary between runs.

if they do, then you will have to define what columns have to match. I'd think that would be #1 (server name) and #8 (no. of cpus), but only you know for sure
James R. Ferguson
Acclaimed Contributor

Re: comparing columns in the text file

Hi (again):

Oops, there is a typographical error in my script:

...

[ -s "${MYDIFF}" && mailx root -s "Files differ!" < ${MYDIFF}

...should be:

[ -s "${MYDIFF}" ] && mailx root -s "Files differ!" < ${MYDIFF}

...which should be obvious, anyway :-)

Regards!

...JRF...