1. #!/bin/bash
    2. #
    3. Date_time=`date +%Y-%m-%d-%H`
    4. pr_domain="/root/domain/111.txt"
    5. dingding_api="https://oapi.dingtalk.com/robot/send?access_token=589d4db1c0e2***9418e07d4a199833031637398ac6cb40c6299d13023ca9ec969d"
    6. #dingding_api="https://oapi.dingtalk.com/robot/send?access_token=740b293ff82c***35de96bfb0e13495eb32e268340db4e7a99e64417b5c9f7e2a43"
    7. cf_api="https://api.cloudflare.com/client/v4/zones/ba6a1d4408c00c2af***450e112fbb1f6d3/custom_hostnames?per_page=250"
    8. cf_user="bob.huo@orderplus.com"
    9. cf_api_key="f6f44711479c29202***f57959ed3060a8f3"
    10. #cloud_www=`cat $pr_domain|grep hostname|awk '{print $2}'|awk -F '"' '{print $2}' >$Domain`
    11. #pull domain from cloudflare
    12. #/usr/bin/curl http://open-api.orderplus.com/site/cloud_domains > $pr_domain
    13. curl -X GET $cf_api -H "X-Auth-Email: $cf_user" -H "X-Auth-Key: $cf_api_key" -H "Content-Type: application/json" >$pr_domain
    14. cat $pr_domain|grep hostname|awk '{print $2}'|awk -F '"' '{print $2}' >/root/domain/cloud_domain.txt
    15. #sed -i 's/\[//g' $pr_domain && sed -i 's/\]//g' $pr_domain && sed -i 's/"//g' $pr_domain && sed -i 's/,/\n/g' $pr_domain && cat $pr_domain > /root/domain/domain.txt
    16. #排除掉已下架的域名
    17. Bad_Domain_txt=$(</root/domain/bad.txt)
    18. for i in $Bad_Domain_txt
    19. do
    20. sed -i "/$i/d" /root/domain/cloud_domain.txt
    21. done
    22. #检测ssl证书
    23. #Domain=$(</root/domain/cloud_domain.txt)
    24. mkdir -p /data/domain/$Date_time
    25. #Domain_txt=$(</root/domain/domain.txt)
    26. for d in `cat /root/domain/cloud_domain.txt`;do /usr/bin/curl -I https://$d >/data/domain/$Date_time/$d.txt;done
    27. ls -l /data/domain/$Date_time|awk '{if($5==0) print $9}' >/data/domain/bad_domain.txt
    28. sed -i 's/.txt//g' /data/domain/bad_domain.txt
    29. sed -i ':a ; N;s/\n/ / ; t a ; ' /data/domain/bad_domain.txt && sed -i 's/ /,/g' /data/domain/bad_domain.txt
    30. Bad=`cat /data/domain/bad_domain.txt`
    31. if test -s /data/domain/bad_domain.txt;then
    32. curl -H "Content-type: application/json" -X POST -d '{"msgtype": "text","text": {"content": "'证书错误域名:$Bad'"}, "at": {"atMobiles": ["'18500164535'"], "isAtAll": false}}' $dingding_api
    33. else
    34. # curl -H "Content-type: application/json" -X POST -d '{"msgtype": "text","text": {"content": "'证书OK'"}, "at": {"atMobiles": ["'18500164535'"], "isAtAll": false}}' $dingding_api
    35. echo "$Date_time.OK" >> /root/domain/okok.txt
    36. fi