[SOLVED] Want to remove output from a command

Hi,

I'm on AIX 5.2. I wrote a script that makes a traceroute to a host. The script works fine but each time it using the traceroute command its generate the 2 output lines.

this is the command in my script

traceroute -n -m 5 -w 2 $Host | grep 172 | awk '{print $2}' | tail -1
  traceroute to XXX.XXX.XXX.XXX (XXX.XXX.XXX.XXX) from XXX.XXX.XXX.XXX (XXX.XXX.XXX.XXX), 5 hops max
  outgoing MTU = 1500
  XXX.XXX.172.XXX

I dont want the 2 first lines to be print out. I didn't find any switch to put the traceroute command in quiet mode... I tried this but it still printing the undesirables lines.

traceroute -n -m 5 -w 2 $Host | grep 172 | awk '{print $2}' | tail -1 > $temp_out 2>/dev/null
  traceroute to XXX.XXX.XXX.XXX (XXX.XXX.XXX.XXX) from XXX.XXX.XXX.XXX  (XXX.XXX.XXX.XXX), 5 hops max
  outgoing MTU = 1500
cat $temp_out
  XXX.XXX.172.XXX

Any idea how I can work around this issue ?

Redirecting tail's stderr won't redirect the undesirable lines, if it's not the thing printing them in the first place. Lines going to standard error don't go through your pipe chain, they go direct from traceroute to the terminal. Redirect traceroute's stderr and they should go away.

traceroute ... 2>/dev/null | command1 | command2 ...
1 Like

Thanks a lot!

It works just fine now!

1 Like