Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (43 sloc) 1.59 KB
#!/bin/bash
LOG="/var/log/dyndns.log"
USER="" #your zerigo email address
PASSWORD="" #your zerigo API Key
key="" #your maildrill API key
from_email="" #who is sending the email
reply_to="$from_email" #reply email address
from_name="DynDNS Updater" #from name
to_email="" #who are we sending the email to?
function log(){
NOW=$(date +"%m-%d-%Y %T")
echo -e "[$NOW][$HOST] - $1" >> $LOG
}
function email(){
if [ $# -eq 3 ]; then
msg='{ "async": false, "key": "'$key'", "message": { "from_email": "'$from_email'", "from_name": "'$from_name'", "headers": { "Reply-To": "'$reply_to'" }, "return_path_domain": null, "subject": "'$2'", "text": "'$3'", "to": [ { "email": "'$1'", "type": "to" } ] } }'
results=$(curl -A 'Mandrill-Curl/1.0' -d "$msg" 'https://mandrillapp.com/api/1.0/messages/send.json' -s 2>&1);
echo "$results" | grep "sent" -q;
if [ $? -ne 0 ]; then
echo "An error occured: $results";
exit 2;
fi
else
echo "$0 requires 3 arguments - to address, subject, content";
echo "Example: ./$0 \"to-address@mail-address.com\" \"test\" \"hello this is a test message\""
exit 1;
fi
}
for i in $*; do
subject="Dyn DNS Updater For $HOST"
HOST=$i
UPDATE=$(wget "http://update.zerigo.com/dynamic?host=${HOST}&user=${USER}&password=${PASSWORD}" -q -O -)
if [ "$UPDATE" = "Nothing to change" ]; then
log "$UPDATE"
elif [ "$UPDATE" = "OK" ]; then
log "$UPDATE"
email "$to_email" "$subject" "$HOST - $UPDATE"
else
log "$UPDATE"
email "$to_email" "$subject" "$HOST - $UPDATE"
fi
echo "[${HOST}] - ${UPDATE}"
done