読者です 読者をやめる 読者になる 読者になる

ValueDomainのダイナミックDNSを更新するGroovyスクリプト

参考: http://blog.iwa-ya.net/2009/10/13/114906

groovyを勉強中なのでgroovyで書いてみた。

def domain = 'example.com'
def password = 'xxxxxxx'
def hosts = ['*','@']

newIpAddress = new URL('http://dyn.value-domain.com/cgi-bin/dyn.fcg?ip').getText()
curIpAddress = InetAddress.getByName(domain).hostAddress

if (newIpAddress != curIpAddress) {
    date = new Date()
    println "$date newIpAddress:$newIpAddress curIpAddress:$curIpAddress"
    hosts.each { host ->
        response = new URL("http://dyn.value-domain.com/cgi-bin/dyn.fcg?d=$domain&p=$password&h=$host&i=$newIpAddress").getText();
        println response
    }
}

cronに適当に登録

* * * * * /usr/local/groovy/bin/groovy /mnt/drbd/ddns/ddns_updater.groovy >> /var/log/ddns.log 2>&1