Last active
August 29, 2015 14:23
-
-
Save fuyuanli/8d9d847a90cd8ebdb4c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #相關設定說明:https://goo.gl/K5ucXJ | |
| #這隻小腳本應該可以丟掉OpenShift內的Cron功能跑,不用自己開機監控:http://www.cystc.org/?p=2940&lang=zh-tw | |
| #判斷依據可以自己找適合的方法寫,如果是虛擬主機掛掉可能就不適合用Ping了,也可以用curl抓網頁字串是否存在來判斷存活 | |
| ping -c 1 -w 10 主機A > /dev/null 2>&1 | |
| if [ $? = 0 ] #判斷主機是否上線 | |
| then #主機A上線,OK | |
| echo "ServerA is live~" | |
| else #主機A離線,修改CloudFlare DNS紀錄。 | |
| curl https://www.cloudflare.com/api_json.html \ | |
| -d 'a=rec_edit' \ | |
| -d 'tkn=Cloudflare_API_Key' \ | |
| -d 'email=Cloudflare_Email_Address' \ | |
| -d 'z=mydomain.com' \ | |
| -d 'id=rec_id' \ | |
| -d 'type=CloudFlare_Record_Type' \ | |
| -d 'name=CloudFlare_Record_Name' \ | |
| -d 'ttl=1' \ | |
| -d "content=主機B" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment