Scripts

Dynamic DNS script to update Linode.com domain records

My Macbook pro died and I decided a get a shiny new Windows laptop that I could convert to a Linux laptop. I partitioned the disk and created a dual boot with Linux Mint and Windows. Linux Mint installled like a champ and has been running happily ever since. I don’t think I have booted to Windows but twice in the last year.

Moving to a new OS did mean that I needed to rewrite some of the scripts I use on a regular basis. One of the scripts updates DNS records at Linode with my current IPv4 and IPv6 WAN addresses and is run as a cron job. It’s a bash script I first wrote about here. The updated script can be found here.

Script: Update Linode DNS Records with WAN IPs (Dynamic DNS)

Either of these scripts will grab both the IPv4 and IPv6 (if any) addresses assigned to any WAN I’m behind, and, using Linode’s DNS API, will update my DNS records with same and log changes/errors using logger. In effect, it’s a homemade Dynamic DNS updater. Linode’s developing a new API so that’s why  two versions exist.

Download from Bitbucket

To use the script, you need:

  1. A Linode API key (for version 3 of Linode’s DNS API) or Personal Access Token (for version 4 of Linode’s DNS API),
  2. the domain ID, and
  3. the resource (called record in v4) IDs of the DNS records you want to update.

The IDs don’t change, whether you’re using version 3 or version 4.

One-Liners

#Handy One-Liners

This page is a collection of random one-liners I’ve used and wanted to keep track of.

list contents of all crontabs

for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done

Script: Assemble NGINX Configuration Files

merge-ngx-conf.pl is a perl script used to assemble a set of nginx configuration files for one site. It has a number of options. See the bitbucket page or the help documentation in the script itself.

In its simplest form, it’s called by issuing this command:

merge-ngx-conf.pl /path/sites-available/filename

The output is an assembled nginx configuration file with all the includes inserted. Using nginx.conf and domain.conf (or just domain.conf depending on the options selected), the script iterates through the include directives in the files and inserts the text from the referenced file. The script handles wildcard masks and follows include directives down multiple levels (i.e. nested levels). It will also follow referenced files in directories external to the nginx configuration directory.

Script: Parse Mail Headers

Here’s a perl script I put together that uses Email::Simple to extract the headers from a message. See link below.

I’m using it to examine spam. It parses all the headers, with a focus on the Received headers. It should be easy to alter it to examine any header you want. As it is currently written, it:

  1. finds all the Received headers
  2. finds the first Received header that was added to the mail (presumably the header added by the first MTA that received it)
  3. extracts the IP from that header
  4. does an rDNS lookup
  5. if there’s a hostname, it looks up the nameservers for the base domain.

By “base domain” I mean that if the rDNS returns a hostname like “1234.my.example.domain.com”, the base domain would be “domain.com”.