2018/03/29

March 29 2018 Tuesday

Weather: sunny
1. Demand: A website, using CDN, there are dozens of nodes all over the country. You need to write a shell script to monitor whether each node is normal.
Such as:

  • The monitored url is www.aiaoxue.top/index.php
  • The source website ip is 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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325446312&siteId=291194637
29