[英]Continue a bash script
After the success view of the host ( IPs ) I need to ping them in order to check if they are up. 在成功查看主机(IP)后,我需要对其进行ping操作,以检查它们是否启动。 SIDS file contains 2 columns with hostnames.
SIDS文件包含2列带有主机名的列。 Are there any suggestions on how to Iimprove the code below?
关于如何改进下面的代码有什么建议吗?
#!/bin/bash
LINES=`cat /home/marko/SIDS | sed "s!/!-!g" | wc -l`
for (( i=1; i<=${LINES}; i++))
do
FIRSTIP=CPE-`sed -n "${i}{p;q}" /home/marko/SIDS | awk '{print $1}'| sed "s!/!-!g"`
SECONDIP=CPE-`sed -n "${i}{p;q}" /home/marko/SIDS | awk '{print $2}'| sed "s!/!-!g"`
COUNT=$( host ${FIRSTIP} | grep address | wc -l )
if [ $COUNT -gt 0 ]
then
echo success
else
echo ${SECONDIP}
fi
done
You can just use dig
, to avoid searching the output of host
: 您可以只使用
dig
,以避免搜索host
的输出:
IP=$(dig +short $SERVERNAME)
Then to check, if the host is alive: 然后检查主机是否还活着:
if ping -q -c $IP >/dev/null 2>&1
then
echo "OK"
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.