LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   diff the output of one bash script against another (https://www.linuxquestions.org/questions/linux-general-1/diff-the-output-of-one-bash-script-against-another-890182/)

Finejason 07-06-2011 04:29 AM

diff the output of one bash script against another
 
Hi guys

I would like to compare the (screen) output of one bash script with the (screen) output of another bash script to ensure the output is exactly the same.

The reason for this is that I am receiving a consolidated data feed from an IP address and have moved some of the data feed to a 'new' source IP address. I will turn off the feed from the original once satisfied that the new is receiving the same data. The format of the output from the scripts are exactly the same.

Tried so far

./IDCGRE.sh | grep FX.CK | diff < ./IDCGRE2.sh
./IDCGRE.sh | grep FX.CK | ./IDCGRE2.sh | diff
diff "./IDCGRE.sh | grep FX.CK" ./IDCGRE2.sh

I'll tail 5 seconds worth of data every 60 seconds into a file for each bash script and then run diff on the output files. Execution start time will cause some differences at the begining/end of file.

Using this helpful method

http://www.bashcookbook.com/bashinfo...ripts/timeout3


Would just like to know if there is a way to compare output rather than files with diff or any other?

colucix 07-06-2011 05:16 AM

Use process substitution:
Code:

diff <(./IDCGRE.sh | grep FX.CK) <(./IDCGRE2.sh | grep FX.CK)
the two outputs will be compared after both the scripts have terminated.

Finejason 07-07-2011 02:21 AM

Thank you colucix!
 
Thanks mate that was very helpful. I have managed to complete the task and now have a way to test feeds in future. My final command looks a little different because I need to remove sequence numbers and a few milliseconds from a portion of each output but your answer was absolutely spot on!

Here's what I ended up with - messy but it seems to work. snapFeed.sh is the timeout script (unchanged!) mentioned in original post.

diff <(./snapFeed.sh -t 25 /home/gtr/vtmfDump/./IDCGRE.sh | ./snapFeed.sh -t 25 grep FX.CK | ./snapFeed.sh -t 25 awk '{print $2 substr($3,0,42) substr($3,45);for (i=4;i<=NF; i++) printf $i;}'
) <(./snapFeed.sh -t 25 /home/gtr/vtmfDump/./IDCGRE2.sh | ./snapFeed.sh -t 25 grep FX.CK | ./snapFeed.sh -t 25 awk '{print $2 substr($3,0,42) substr($3,45);for (i=4;i<=NF; i++) printf $i;}'
)


Once again, thanks for the help.

colucix 07-07-2011 02:41 AM

You're welcome! :)


All times are GMT -5. The time now is 11:20 PM.