Batch file 将Windows批处理文件转换为Linux shell脚本
我有一个批处理文件,用来检查我的站点是否对ping做出反应。 如果站点没有反应,脚本会将输出写入文本文件 我想在Linux系统上使用同样的脚本 有人能帮我翻译代码,这样我就可以在Linux shell上使用它了吗Batch file 将Windows批处理文件转换为Linux shell脚本,batch-file,shell,ping,Batch File,Shell,Ping,我有一个批处理文件,用来检查我的站点是否对ping做出反应。 如果站点没有反应,脚本会将输出写入文本文件 我想在Linux系统上使用同样的脚本 有人能帮我翻译代码,这样我就可以在Linux shell上使用它了吗 set list=domains.txt If "%list%" =="" GoTo EXIT for /f "eol=; tokens=1*" %%i in (%list%) do ping -n 1 -w 1 www.%%i >> no-response.txt; 非
set list=domains.txt
If "%list%" =="" GoTo EXIT
for /f "eol=; tokens=1*" %%i in (%list%) do ping -n 1 -w 1 www.%%i >> no-response.txt;
非常感谢除了1毫秒的超时之外的一切:
while read DOMAIN
do
ping -c 1 -W 1 "www.${DOMAIN}" >dev/null || echo "${DOMAIN}" >>"no-response.txt"
done <"domains.txt"
读取域时
做
ping-c1-w1“www.${DOMAIN}”>dev/null | | echo“${DOMAIN}”>>“no response.txt”
完成更新。这将评估ping命令是否成功
#!/bin/sh
list=`cat domains.txt`
for domain in $list ; do
ping -c 1 -W 1 www.$domain
if [ "$?" -ne "0" ] ; then
echo $domain >> no-response.txt
fi
done
读取域时
做
ping-c1“$domain”-W2 1>/dev/null | | echo“无响应:$domain”>>No-response.txt
完成<“文件”
谢谢道格拉斯,可以ping的域列在“no response.txt”文件中。有没有办法得到没有响应的域名。
while read domain
do
ping -c1 "$domain" -W2 1> /dev/null || echo "No response: $domain" >> no-response.txt
done < "file"