从traceroute命令数据解析 [英] Parsing data from traceroute command

查看:175
本文介绍了从traceroute命令数据解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图解析从路由跟踪命令和输出它与bash脚本价值跳数。

任何提示?很新这样的感谢。

我的脚本看起来像这样至今:

 #!/斌/庆典
#parse进行路由跟踪啤酒花和输出到标准输出。
呼应-n输入主机名(如www.google.com):
读主机名
traceroute的2 - ;&放大器; 1 $主机名| grep的跳跃
回声跳数是


解决方案

您是否正在寻找花跳数,或者64跳最大的价值?如果是前者,使用来获取输出的最后一行,则 AWK 打印第一列:

 <$ C C> traceroute的$主机名2  - ;的/ dev / null的|尾-1 | AWK'{打印$ 1}

I am trying to parse the "number of hops" value from the traceroute command and output it with a bash script.

Any hints? Very new so thanks.

My script looks like this so far:

#!/bin/bash
#parse traceroute for hops and output to stdout.
echo -n "Enter a host name(like www.google.com):  "
read hostname
traceroute 2>&1 $hostname|grep "hops"
echo "number of hops are "

解决方案

Are you looking for the number of hops it took, or the "64 hops max" value? If it's the former, use tail to get the last line of output, then awk to print the first column:

traceroute "$hostname" 2>/dev/null | tail -1 | awk '{print $1}'

这篇关于从traceroute命令数据解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆