Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare output files

Status
Not open for further replies.

rn4it

MIS
Nov 7, 2002
671
CA
I have an expect script that runs some basic commands on a router and writes the output to a logfile thats date stamped. This is part of morning checks, which are then emailed to me for me to review. I'm not a heavy unix user or programer, but what I'd like to do is create a small script to compare certain field or just pull out cetain fields redirect is another file which is then emailed What I'm wondering is what would be the best way to do the following tasks with which filtering command.

*search router1.270109 output file for the following line and output it to the file to be emailed. Note: the uptime changes. So I'd need to be able to pull the entire line.

BGP state = Established, up for 45w3d

* seach router1.270109 and router1.2601009
pull the interface resets or collisions from the 2 file and compare them and place the output to the file to be email.

1 output errors, 0 collisions, 1 interface resets

any help would be appreciated.

 
A shell script using grep or egrep and awk would do the trick. What does the log file look like and how are the fields on each line seperated?

To be a great teacher, one does not provide answers, but methods to help your students find the answers

bsh

35 years Bell, AT&T, Lucent, Avaya
Tier 3 for 25 years and counting
 
examples of the output are above,
I copied the below 2 lines out of the one log file.
The one below this is taken from a show ip bgp neighbor command. All I want to pull from it is the 45w3d. I have an idea how to pull it if it always stayed that value. Since it changes on a daily basis. I would need to know how to pull whatever value is in that position in the file. This I have no idea on.
BGP state = Established, up for 45w3d

This one is similar as the above but comparing the number of collisions from yesterday to today and print the difference. Since the value could change at any point in time I'd have to state pull the content of row 15 and column 4 to extract the 0. once again no idea.
1 output errors, 0 collisions, 1 interface resets

thanks
 
egrep BGP.*stat.*Estab logfilename | awk '{print $7}'

egrep uses regular expression to find all lines that match
and the | awk will print arg 7 on the line



A great teacher, does not provide answers, but methods to teach others "How and where to find the answers"



bsh

35 years Bell, AT&T, Lucent, Avaya
Tier 3 for 25 years and counting
 
Very cool, thanks. Now at least I know that I'm on the right track. Go back to the tutorials and start piecing the report together.

thanks again.
 
you could get really fancy with the awk print

BGP state = Established, up for 45w3d

egrep BGP.*stat.*Estab logfilename | awk '{print "status = "$5", location = "$7}'

status = up, location = 45w3d




A great teacher, does not provide answers, but methods to teach others "How and where to find the answers"



bsh

35 years Bell, AT&T, Lucent, Avaya
Tier 3 for 25 years and counting
 
Than's great, when I use the first cmd egrep BGP.*stat.*Estab logfilename | awk '{print $7}' I get 2 replies because the router that the command comes from has 2 BGP neighbors. What I was thinking redirecting it to a temp file. Then pull it out of the file one at a time to create the format that I want.
example
egrep BGP.*stat.*Estab logfilename | awk '{print $7}'
returns
45w2d
49w2d

ISP connection 1 up for 45w2d
ISP connection 2 up for 49wd

what do you think?
thanks

 
look up at my last post

A great teacher, does not provide answers, but methods to teach others "How and where to find the answers"



bsh

35 years Bell, AT&T, Lucent, Avaya
Tier 3 for 25 years and counting
 
egrep BGP.*stat.*Estab logfilename | awk '{print "status = "$5", location = "$7}'

status = up, location = 45w3d
status = up, location = 49w2d


A great teacher, does not provide answers, but methods to teach others "How and where to find the answers"



bsh

35 years Bell, AT&T, Lucent, Avaya
Tier 3 for 25 years and counting
 
Sorry, what I mean is the 1 router has 2 BGP connections. 1 to ISP A and 1 to ISP B. I want to have it say something like.
status = up, ISP A = 45w3d
status = up, ISP B = 49w2d

If use the command you last suggested it would have the both be the same ISP. Do you see what I mean or am I still missing something?

thanks your help is greatly appreciated.
 
I am just showing you the print option for awk so you could do this on the command line with a one line script then redirect it. You could have a second script re-format the data with more comprehensive formatting.

A great teacher, does not provide answers, but methods to teach others "How and where to find the answers"



bsh

35 years Bell, AT&T, Lucent, Avaya
Tier 3 for 25 years and counting
 
Ok, thanks,
The examples are very helpful and give me a great place to start.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top