Created
November 17, 2015 11:40
-
-
Save napcae/7b2ee4dadeca60231a00 to your computer and use it in GitHub Desktop.
update dynamic dns IP for digital ocean
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/bash | |
# No Fallback, no error handling | |
# crontab -e | |
# hourly | |
# 0 * * * * <PATH-TO-SCRIPT>/update_drop_dyn.sh $api_key $domain $record > <PATH-TO-LOGFILE> 2>&1 | |
##### | |
# note: don't forget to add a trailing colon(:) to the $api_key to avoid a password prompt from the api | |
api_key="$1" | |
domain="$2" | |
record_id="$3" | |
function get_externalIP { | |
curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z/<> :]//g' | tr -d '\r' | |
} | |
externalIP_new=$(get_externalIP) | |
function update_record { | |
curl -X PUT -H 'Content-Type: application/json' -u ${api_key} -d '{"name":"home","data":"'${externalIP_new}'"}' "https://api.digitalocean.com/v2/domains/${domain}/records/${record_id}" | |
} | |
update_record |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment