help with ksh parsing traceroute output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with ksh parsing traceroute output
# 1  
Old 11-23-2009
Power help with ksh parsing traceroute output

Good day. I am doing an enq -WA (AIX), to get a list of the print queues, I then compare that to the /etc/hosts file to 'match' the IP address associated with the print queues. What I want to do is to run a traceroute with up to 5 hops, and perform an output to a file with some "specific items". Here is what I have so far...

Code:
#!/bin/ksh
# -- Variables --
HOSTS=/etc/hosts
CFG=/tmp/pqueue.cfg.$$
TROUTE=/tmp/troute.log.$$

for i in `/usr/bin/enq -WA | grep -v ^Queue | grep -v -- ^----- | cut -f 1 -d \ ` ; do grep $i $HOSTS ; done | grep -v ^\# | awk {'print "define host{\n \tuse\t\tgeneric-printer\n\thost_name\t"$2"\n\taddress \t"$1"\n\thostgroups\tdi-printers\n"'} > CFG

for j in `cat $CFG | grep address | cut -f 2 -d \ ` ; do echo "\n" "$j" && traceroute -q2 -m5 $j | awk '{print $3}' | grep "(" | tr -d "(" | tr -d ")" | tr "\n" "," ; done | sed s/\,//2 > $TROUTE


Does anyone have a better way of doing this. What I want to do is get a list of all of the Print Queues and their IP addresses, as well as the Parents (from the Traceroute hops) and output it all into a text file which would be acceptable for nagios.

Any help would be appreciated, and yes as you have probably gathered I am quite a Newb when it comes to shell scripting.

Last edited by Franklin52; 11-24-2009 at 04:32 AM.. Reason: Please use code tags!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh parsing arguments in a string rather than from the cmdln

Hi. I have a piece of code that reads and parses command line options. I'd like to alter it slightly to read from a string (that's set elsewhere in the script) rather than directly from the command line (arg). Can somebody show me how to do this? Many thanks. My code is as follows: typeset... (6 Replies)
Discussion started by: user052009
6 Replies

2. Shell Programming and Scripting

Parsing ksh script

Is there any tool that can parsing ksh script into grammar format? e.g. the tool can parse the following ksh script: echo "hello"> abc.txt cp /home/user/abc/.profile /home/user/abc/myprofile into GENERATE abc.txt COPY /home/user/abc/.profile TO /home/user/abc/myprofile My server OS... (2 Replies)
Discussion started by: cstsang
2 Replies

3. Shell Programming and Scripting

XML parsing in KSH

Hi All, Although I was able to find past XML parsing questions, as the questions were a little different than this, I had a pretty hard time adapting those answers to this scenario. -> May I ask if anyone knows how to extract the IP addresses of the below "servers.xml" file into an array... (5 Replies)
Discussion started by: chatguy
5 Replies

4. Shell Programming and Scripting

Traceroute script weird output

This script is giving weird output #!/bin/bash NETPATH=(`/bin/traceroute -n 4.2.2.2 | awk '{print $2}'`) for i in "${NETPATH}" do echo $i done The output: to 11.11.11.1 1.1.1.1 99.111.208.2 traceroute_test.sh traceroute_test.sh (7 Replies)
Discussion started by: thumbs
7 Replies

5. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

6. Shell Programming and Scripting

Need help parsing config file in ksh

Hi all, I've done some searching here but haven't found exactly what I'm looking for so I thought I'd post up and see if someone can help out. I'm working on a shell script that I would like to store environment variables in an external file. I'm familiar with sourcing a file with variables in... (1 Reply)
Discussion started by: kungfusnwbrdr
1 Replies

7. IP Networking

Puzzling Traceroute output

This is the output that I get every so often when trying to do a traceroute to the web server whenever it's inaccessible: traceroute to 64.40.98.181 (64.40.98.181), 30 hops max, 40 byte packets 1 207.97.207.194 (207.97.207.194) 2.625 ms 2.840 ms 2.968 ms 2 core1-5.iad1.rackspace.com... (6 Replies)
Discussion started by: gaspol
6 Replies

8. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

9. Shell Programming and Scripting

Parsing and getting data from XML file using ksh script

Hi All, I have a xml file for example as described below <xml> <address> <street><street> <address/> <isbn>426728783932020308393930303</isbn> <book> <name> </name> </book> . . . </xml> My problem is to get the isbn number from the above described file using ksh script. Could... (6 Replies)
Discussion started by: vinna
6 Replies

10. UNIX for Dummies Questions & Answers

traceroute output?

I understand the concept of traceroute - can anyone explain the output to me e.g. 39ms 39ms 39ms are these the times for each trip it takes? Assuming each machine is pinged 3 times. and how does the RTT work? Is this the time it takes from one machine to another because it doesn't look like... (6 Replies)
Discussion started by: justine petrie
6 Replies
Login or Register to Ask a Question