脚本ping和traceroute bash

发布于 2025-01-21 18:43:18 字数 609 浏览 3 评论 0原文

早上好,我想创建一个脚本,使我可以从IP列表中ping和traceroute进行ping和traceroute,我已经开始制作这个小脚本。我遇到的问题是:脚本ping和tracerout仅文件的最后一个IP,我无法将ping结果导出到另一个文件,

#!/bin/bash
# in order:
# - saintpierre
# - ping and traceroute saintpierre
FILENAME="./ip/sainpierre/ipsaintpierre.txt"
sudo mkdir ./result/saintpierre/
outputfile="./result/saintpierre/$(date "+%F-%Hh%Mm%S")-$pingtestlogsaintpierre.txt"
for DC in $FILENAME
do
    printf "$DC: \t$(ping -i .2 -c 10 -q $DC | awk -F/ '/^round|^rtt/{print $5}') ms\n" | expand -t 20
done >>$outputfile
echo -e "\n"
traceroute $FILENAME >>$outputfile

谢谢

Good morning, I would like to create a script that allows me to ping and traceroute from a list of ip, I have already started to make this little script. the problems I encounter are : that the script pings and traceroutes only the last ip of the file and I can't export the ping results to another file

#!/bin/bash
# in order:
# - saintpierre
# - ping and traceroute saintpierre
FILENAME="./ip/sainpierre/ipsaintpierre.txt"
sudo mkdir ./result/saintpierre/
outputfile="./result/saintpierre/$(date "+%F-%Hh%Mm%S")-$pingtestlogsaintpierre.txt"
for DC in $FILENAME
do
    printf "$DC: \t$(ping -i .2 -c 10 -q $DC | awk -F/ '/^round|^rtt/{print $5}') ms\n" | expand -t 20
done >>$outputfile
echo -e "\n"
traceroute $FILENAME >>$outputfile

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

找回味觉 2025-01-28 18:43:18

假设您需要创建路径/结果/saintpierre/,则需要使用-p参数:-p

mkdir -p /result/saintpierre/

将在路径中创建所有文件夹,

因为您需要读取文件以使所有IP循环中的所有IPS,您必须更改为:

for DC in $(cat $FILENAME)

Assuming you need to create the path /result/saintpierre/, you need to use -p parameter:

mkdir -p /result/saintpierre/

-p will create all folders in path

Since you need to read a file to get all IPs on loop, you have to change to:

for DC in $(cat $FILENAME)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文