Skip to content

Instantly share code, notes, and snippets.

@UniIsland
Created February 10, 2018 16:39
Show Gist options
  • Save UniIsland/362bff859f0045e09d5ee5b278eca85a to your computer and use it in GitHub Desktop.
Save UniIsland/362bff859f0045e09d5ee5b278eca85a to your computer and use it in GitHub Desktop.
update linode dns record with ruby
#!/usr/bin/env ruby
require 'rubygems'
require 'linode'
api_key = '<API_KEY_STRING>'
domain_id = 123456 # Domain ID
resource_id = 7654321 # Resource ID
new_ip = `ifconfig | grep "inet " | grep -v '127.0.0'`.split(' ')[1]
abort unless new_ip.match /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/
l = Linode.new :api_key => api_key
result = l.domain.resource.list :domainid => domain_id, :resourceid => resource_id
old_ip = result[0].target
if old_ip == new_ip
puts "[no change] #{old_ip}"
else
l.domain.resource.update :domainid => domain_id, :resourceid => resource_id, :target => new_ip
puts "[updated] #{old_ip} -> #{new_ip}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment