2018/03/29

March 29 2018 Tuesday

Weather:suny
1、需求:一个网站,使用了cdn 全国各地有几十个节点。需要你写一个shell脚本来监控各个节点是否正常。
如:

  • 监控的url为www.aiaoxue.top/index.php
  • 源网站ip为8.8.8.8
[root@Dasoncheng sbin]# cat d.sh 
#!/bin/bash
##monitor the cdn site is ok?
url="www.aiaoxue.top/index.php"
sip="8.8.8.8"
curl -x $sip:80 $url > /tmp/source.html 2>/dev/null

for ip in `cat ip.txt`;
do
  curl -x $ip:80 $url > /tmp/cdn.html 2>/dev/null
  diff /tmp/source.html /tmp/cdn.html &>/dev/null
  if [ ! $? -eq 0 ];
  then
      echo "The ip $ip is wrong!"
  fi
done

answer referred

#!/bin/bash

url="www.aming.com/index.php"
s_ip="88.88.88.88"
curl -x $s_ip:80 $url > /tmp/source.html 2>/dev/null

for ip in `cat /tmp/ip.txt`
do
    curl -x $ip:80 $url 2>/dev/null >/tmp/$ip.html
    [ -f /tmp/$ip.diff ] && rm -f /tmp/$ip.diff
    touch /tmp/$ip.diff
    diff /tmp/source.html /tmp/$ip.html > /tmp/$ip.diff 2>/dev/null
    n=`wc -l /tmp/$ip.diff|awk '{print $1}'`
    if [ $n -lt 0 ]
    then
        echo "node $ip sth wrong."
    fi
done

猜你喜欢

转载自my.oschina.net/u/3651233/blog/1787136