通过mtr脚本,定位网络故障点

以Centos7 为例:

一、安装mtr软件


yum install -y mtr

 

二、在home目录下新建一个文件mtr.sh,然后往文件中输入以下内容:


#!/bin/bash
ip=(
120.197.84.65
218.205.128.1
120.193.0.1
211.162.78.1
211.161.159.1
211.161.192.1
)
for ((i=0;i<${#ip[@]};i++));do { mtr -r -c 30 -n ${ip[$i]}|sed '1d'|awk 'BEGIN{print "----------------------'"${ip[$i]}"'------------------------"strftime("%Y/%m/%d %H:%M:%S")}{print $0}END{print "\n"}' >>/home/${ip[$i]}.txt &
}
done

 

三、给mtr文件设置可执行权限

chmod 755 mtr.sh

 

四、将文件加入crontab中,让该文件每分钟执行一次

1、执行:

crontab  -e

 

2、输入:

*/1 * * * * /home/mtr.sh

 

发表回复

Your email address will not be published.

名字 *
电子邮件 *
站点