Traceroute script weird output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Traceroute script weird output
# 1  
Old 04-02-2011
Traceroute script weird output

This script is giving weird output

Code:
#!/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
traceroute_test.sh
131.164.43.240
151.177.55.186
4.68.62.37
4.69.234.158
4.234.9.140.193
4.69.138.35
4.2.2.2


The lines that are displaying "traceroute_test.sh" are lines that would normally show * * * during a regular traceroute.

Also unless I run this script in a directory where there are no other files, all files are listed in the out put when I run the script.

Finally, I am using AWK because otherwise I was getting each column/element of the traceroute on a new line instead of each hop being on its own line.

So:

1) why is the name of the script showing up in the output?
2) why if there are other files in the dir the script is in are the files getting listed when I run the script?
3) also how do I keep the script from interperting every element in the output of trace route as a seperate line?
# 2  
Old 04-02-2011
Code:
echo "$i"

# 3  
Old 04-02-2011
No change:

Code:
#!/bin/bash

#NETPATH=(`/bin/traceroute -n 4.2.2.2 | awk '{print $2}'`)
NETPATH=(`/bin/traceroute -n 4.2.2.2 `)

#echo ${NETPATH[@]}

for i in "${NETPATH[@]}"
   do 
        echo "$i"
done

OUTPUT:

Code:
to
4.2.2.2
(4.2.2.2),
30
hops
max,
40
byte
packets
1
11.11.11.1
1.089
ms
1.068
ms
1.059
ms
2
1.1.1.1
3.867
ms
3.933
ms
3.998
ms
3
traceroute_test.sh
traceroute_test.sh
traceroute_test.sh
4
traceroute_test.sh
traceroute_test.sh
traceroute_test.sh
5
traceroute_test.sh
traceroute_test.sh
traceroute_test.sh
6
11.144.214.12
13.525
ms
12.765
ms
traceroute_test.sh
7
121.164.123.132
11.713
ms
9.647
ms
9.639
ms
8
151.164.22.186
16.910
ms
11.117
ms
12.546
ms
9
4.68.62.181
30.343
ms
4.68.62.37
30.527
ms
30.810
ms
10
4.69.138.158
29.556
ms
29.800
ms
29.663
ms
11
4.69.140.193
42.564
ms
4.69.140.189
33.913
ms
4.69.140.193
41.961
ms
12
4.69.138.35
30.019
ms
31.263
ms
30.018
ms
13
4.2.2.2
30.318
ms
30.769
ms
30.483
ms


I am fine with using AWK to get the IP. But I don't understand why I am getting the name of the script as output on hops that are not returning an IP. Also as I mentioned earlier why do files that are in the same directory show up as put?

Last edited by vgersh99; 04-02-2011 at 01:17 PM.. Reason: code tags for DATA as well
# 4  
Old 04-02-2011
Code:
NETPATH="(`/bin/traceroute -n 4.2.2.2 `)"

please post the output of /bin/traceroute -n 4.2.2.2 using code tags!

Last edited by vgersh99; 04-02-2011 at 01:16 PM..
# 5  
Old 04-02-2011
The pathname expansion is happening because the asterisks generated by the command substitution are unquoted. The *'s become the list of files before the result is stored in NETPATH.

Regards,
Alister
# 6  
Old 04-02-2011
DUDE!

Thanks

Sorry about not using the code tags.
# 7  
Old 04-02-2011
The whole script as posted can be replaced with:

Code:
#!/bin/bash
/bin/traceroute -n 4.2.2.2 2>&1

An environment variable like $NETPATH is not a file.

What does a sample "traceroute" on your computer look like?
What is you expected output?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Weird output from ps command

Hi Guys, I am regular Solaris user. I came across a weird problem that puzzled me. Hope you guys can help. I found that process's state(command & arguments) in two different variants of ps command is different. Can anyone explain how is this possible? bash-3.2$ ps -eLo pid,s,comm,args |... (2 Replies)
Discussion started by: brij123
2 Replies

2. HP-UX

[Solved] Weird 'ls -l' output

Hello folks, I've found an HP-UX server with a rare 'ls -l' output. Please see the attached file. Anybody knows how can I change the output to not have this extra tabulations? Thanks in advance! (10 Replies)
Discussion started by: carpannav
10 Replies

3. Shell Programming and Scripting

Weird tail output over ssh

Hello; Am trying to correct the formatting of tail output over ssh. Using the following code: echo "" > $FILE for BOX in $SERVERS do echo "Processing on $BOX" |tee -a $FILE echo "===============================" >> $FILE sudo ssh $BOX 'TERMINAL="vt100" /usr/bin/sh -s' <... (2 Replies)
Discussion started by: delphys
2 Replies

4. UNIX for Dummies Questions & Answers

weird 'ls' output

Hi, Anyone knows why I can't display the contents of my directory and how to fix this? http://i50.tinypic.com/4smfth.jpg Thanks in advance for any advise. Deanne Double post. Continued here. (0 Replies)
Discussion started by: Deanne
0 Replies

5. Shell Programming and Scripting

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".... (0 Replies)
Discussion started by: smurphy_it
0 Replies

6. Shell Programming and Scripting

format of output is weird

hi all, have a ksh script which connects to a database and runs a sql and dumps it to a '.csv' file. The problem is the result is in multiple rows with long spaces in between when it should be just a single line and this screws up the format in the '.csv' file. script is : #!/bin/ksh... (1 Reply)
Discussion started by: cesarNZ
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

weird echo output?

#!/bin/bash INPUT=$1 if then INPUT=0$1 TRACKNUMBER=$INPUT fi TRACKNUMBER=$INPUT echo "Track Number:" $TRACKNUMBER if then echo "File Does Not Exist!: split-track"${TRACKNUMBER}".wav" exit 0 fi CUEFILE="$2" (6 Replies)
Discussion started by: TinCanFury
6 Replies

9. AIX

Weird bootlist output

just setup a new system today - 9117 570, using HMC for console but not partitioned. I installed this system twice. the first time it started off as 5300-00, then updated to ML03. before the update, I believe I mirrored the rootvg, and then altered the bootlist, at that point, the display was... (4 Replies)
Discussion started by: davew1099
4 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