尝试通过传递 listweb.txt 来制作一个 ping .sh 脚本来查看网络是否存在
Trying to make a ping .sh script to see if a web is alive by passing a listweb.txt
所以我正在尝试 ping list.txt 中的一些 URL 并查看是否有效
代码在这里:
url_list=./listawebmin.txt
contador=0
contadorerror=0
contadorsuccess=0
while read siteurl
do
echo "Se va a realizar ping a $siteurl"
if ping -c3 $siteurl
then
echo "---$siteurl SUCCESS---" &>> success.txt
let contadorsuccess=contadorsuccess+1
else
echo "---$siteurl ERROR---" &>> error.txt
let contadorerror=contadorerror+1
fi
let contador=contador+1
done < $url_list
echo "Total de urls : $contador"
echo "Total de urls SUCCESS: $contadorsuccess"
echo "Total de urls ERROR: $contadorerror"
echo "Servicio Terminado mira error.txt"
问题是,当我尝试传递 ping 一个 $something 变量时,例如 something=www.google.com 在这种情况下,ping 没有按预期响应。
说出类似名称或服务未识别的内容(西班牙语::Nombre o servicio desconocido)
所以问题是我如何让它识别 $siteurl ?有没有更好的方法来验证网络是否存在?
编辑:
listawebmin.txt 示例:
www.helenarohner.com
www.100porcienmexico.es
www.24fab.com
www.masllorensestudi.com
www.3i-ingenieria.com
www.360corporate.com
www.7camiciemadrid.es
www.centrodereuniones.com
www.ab-internacional.com
www.aba-abogadas.com
www.google.com
这是一个简单的txt
给你试试这个。
#!/bin/sh
url_list=./listawebmin.txt
contador=0
contadorerror=0
contadorsuccess=0
for siteurl in $(cat $url_list)
do
echo "Se va a realizar ping a $siteurl"
if ping -c3 $siteurl
then
echo "---$siteurl SUCCESS---" &>> success.txt
let contadorsuccess=contadorsuccess+1
else
echo "---$siteurl ERROR---" &>> error.txt
let contadorerror=contadorerror+1
fi
let contador=contador+1
done
echo "Total de urls : $contador"
echo "Total de urls SUCCESS: $contadorsuccess"
echo "Total de urls ERROR: $contadorerror"
echo "Servicio Terminado mira error.txt"
如果这些是网站,我建议测试它们是否正在侦听端口 80。这将排除任何 ping 问题。
可以使用netcat测试80端口是否开放:
#!/bin/bash
host_list=./listawebmin.txt
contador=0
contadorerror=0
contadorsuccess=0
while read -r host; do
if nc -zw2 "$host" 80 &>/dev/null; then
echo "---$host SUCCESS---" >> success.txt
(( contadorsuccess++ ))
else
echo "---$host ERROR---" >> error.txt
(( contadorerror++ ))
fi
(( contador++ ))
done < "$host_list"
echo "Total de hosts : $contador"
echo "Total de hosts SUCCESS: $contadorsuccess"
echo "Total de hosts ERROR: $contadorerror"
echo "Servicio Terminado mira error.txt"
感谢大家的回答我发现 wget 是最好的选择,感谢您的想法!
url_list=./listaweb2.txt
contador=0
contadorerror=0
contadorsuccess=0
while read siteurl
do
echo "Se va a realizar wget a $siteurl"
wget --timeout=3 --tries=1 --spider $siteurl
if [ $? -eq 0 ];
then
echo "---$siteurl is UP---" &>> ./results/success.txt
contadorsuccess=$(expr $contadorsuccess + 1)
else
echo "---$siteurl is DOWN---" &>> ./results/error.txt
contadorerror=$(expr $contadorerror + 1)
fi
contador=$(expr $contador + 1)
done < $url_list
echo "Total de urls : $contador" &>> ./results/resume.txt
echo "Total de urls SUCCESS: $contadorsuccess" &>> ./results/resume.txt
echo "Total de urls ERROR: $contadorerror" &>> ./results/resume.txt
echo "Total de urls UP and running: $contadorsuccess" &>> ./results/success.txt
echo "Total de urls DOWN: $contadorerror" &>> ./results/error.txt
echo "Servicio Terminado mira error.txt"
这是脚本的最终结果
www.helenarohner.com
www.100porcienmexico.es
www.24fab.com
www.masllorensestudi.com
www.3i-ingenieria.com
www.360corporate.com
www.7camiciemadrid.es
www.centrodereuniones.com
www.ab-internacional.com
www.aba-abogadas.com
这是 listaweb2.txt
上的内容示例
PD: if you have a better solution to solve this problem dont doubt to post it even if this gets 10y old i might read it
所以我正在尝试 ping list.txt 中的一些 URL 并查看是否有效 代码在这里:
url_list=./listawebmin.txt
contador=0
contadorerror=0
contadorsuccess=0
while read siteurl
do
echo "Se va a realizar ping a $siteurl"
if ping -c3 $siteurl
then
echo "---$siteurl SUCCESS---" &>> success.txt
let contadorsuccess=contadorsuccess+1
else
echo "---$siteurl ERROR---" &>> error.txt
let contadorerror=contadorerror+1
fi
let contador=contador+1
done < $url_list
echo "Total de urls : $contador"
echo "Total de urls SUCCESS: $contadorsuccess"
echo "Total de urls ERROR: $contadorerror"
echo "Servicio Terminado mira error.txt"
问题是,当我尝试传递 ping 一个 $something 变量时,例如 something=www.google.com 在这种情况下,ping 没有按预期响应。 说出类似名称或服务未识别的内容(西班牙语::Nombre o servicio desconocido) 所以问题是我如何让它识别 $siteurl ?有没有更好的方法来验证网络是否存在?
编辑: listawebmin.txt 示例:
www.helenarohner.com
www.100porcienmexico.es
www.24fab.com
www.masllorensestudi.com
www.3i-ingenieria.com
www.360corporate.com
www.7camiciemadrid.es
www.centrodereuniones.com
www.ab-internacional.com
www.aba-abogadas.com
www.google.com
这是一个简单的txt
给你试试这个。
#!/bin/sh
url_list=./listawebmin.txt
contador=0
contadorerror=0
contadorsuccess=0
for siteurl in $(cat $url_list)
do
echo "Se va a realizar ping a $siteurl"
if ping -c3 $siteurl
then
echo "---$siteurl SUCCESS---" &>> success.txt
let contadorsuccess=contadorsuccess+1
else
echo "---$siteurl ERROR---" &>> error.txt
let contadorerror=contadorerror+1
fi
let contador=contador+1
done
echo "Total de urls : $contador"
echo "Total de urls SUCCESS: $contadorsuccess"
echo "Total de urls ERROR: $contadorerror"
echo "Servicio Terminado mira error.txt"
如果这些是网站,我建议测试它们是否正在侦听端口 80。这将排除任何 ping 问题。
可以使用netcat测试80端口是否开放:
#!/bin/bash
host_list=./listawebmin.txt
contador=0
contadorerror=0
contadorsuccess=0
while read -r host; do
if nc -zw2 "$host" 80 &>/dev/null; then
echo "---$host SUCCESS---" >> success.txt
(( contadorsuccess++ ))
else
echo "---$host ERROR---" >> error.txt
(( contadorerror++ ))
fi
(( contador++ ))
done < "$host_list"
echo "Total de hosts : $contador"
echo "Total de hosts SUCCESS: $contadorsuccess"
echo "Total de hosts ERROR: $contadorerror"
echo "Servicio Terminado mira error.txt"
感谢大家的回答我发现 wget 是最好的选择,感谢您的想法!
url_list=./listaweb2.txt
contador=0
contadorerror=0
contadorsuccess=0
while read siteurl
do
echo "Se va a realizar wget a $siteurl"
wget --timeout=3 --tries=1 --spider $siteurl
if [ $? -eq 0 ];
then
echo "---$siteurl is UP---" &>> ./results/success.txt
contadorsuccess=$(expr $contadorsuccess + 1)
else
echo "---$siteurl is DOWN---" &>> ./results/error.txt
contadorerror=$(expr $contadorerror + 1)
fi
contador=$(expr $contador + 1)
done < $url_list
echo "Total de urls : $contador" &>> ./results/resume.txt
echo "Total de urls SUCCESS: $contadorsuccess" &>> ./results/resume.txt
echo "Total de urls ERROR: $contadorerror" &>> ./results/resume.txt
echo "Total de urls UP and running: $contadorsuccess" &>> ./results/success.txt
echo "Total de urls DOWN: $contadorerror" &>> ./results/error.txt
echo "Servicio Terminado mira error.txt"
这是脚本的最终结果
www.helenarohner.com
www.100porcienmexico.es
www.24fab.com
www.masllorensestudi.com
www.3i-ingenieria.com
www.360corporate.com
www.7camiciemadrid.es
www.centrodereuniones.com
www.ab-internacional.com
www.aba-abogadas.com
这是 listaweb2.txt
上的内容示例PD: if you have a better solution to solve this problem dont doubt to post it even if this gets 10y old i might read it