Created
May 6, 2015 10:41
-
-
Save tekei/b87bc622e4f4add1e5f8 to your computer and use it in GitHub Desktop.
グローバルIP変化監視。変化したらprowlに通知。
This file contains 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/sh | |
IP_ADDR_FILE="/var/lib/jenkins/current_global_ip" | |
CURRENT_IP_ADDR=`curl --max-time 10 -s http://inet-ip.info/` | |
CURL_STATUS=$? | |
if [ ${CURL_STATUS} -ne 0 ]; then | |
echo "error HTTP response / connect NG" | |
exit 1 | |
fi | |
if [ `echo ${CURRENT_IP_ADDR} | wc | awk '{print $3}'` -gt 17 ]; then | |
echo "error request / connect OK" | |
exit 2 | |
fi | |
PREV_IP_ADDRESS=`cat ${IP_ADDR_FILE}` | |
PROWL_URL="https://api.prowlapp.com/publicapi/add" | |
PROWL_API_KEY="##########" | |
PROWL_PARAM="priority=2&application=Network&event=portal" | |
if [ "x${PREV_IP_ADDRESS}" != "x${CURRENT_IP_ADDR}" ]; then | |
echo "ip address change : ${PREV_IP_ADDRESS} -> ${CURRENT_IP_ADDR}" | |
echo "${CURRENT_IP_ADDR}" > ${IP_ADDR_FILE} | |
PROWL_MSG="ip%20address%20change%20:%20${PREV_IP_ADDRESS}%20-%3E%20${CURRENT_IP_ADDR}" | |
curl "${PROWL_URL}?apikey=${PROWL_API_KEY}&${PROWL_PARAM}&description=${PROWL_MSG}" | |
exit 0 | |
fi | |
echo "ip address not change : ${CURRENT_IP_ADDR}" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment