AWS dynamic IP ranges

Need to know the dynamic IP ranges used by AWS in a specific region? AWS publishes this as a JSON file.

curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq '.prefixes | .[] | select((.region == "eu-west-1") and (.service == "EC2")) | .ip_prefix' | sed 's/"//g'

This filters for EC2 in eu-we[……]

Read more

The politics of the Linux desktop

Open Source software was becoming more and more popular in 2009, even though many of these applications were still little known. According to PCWorld, here are ten of the greatest.

Firefox — The open source browser that challenged Internet Explorer and changed the web.

Chromium — The open source pro[……]

Read more

Find sdx device/ATAx mappings

When dealing with hardware, you often see log messages like:

ata9: hard resetting link
ata9: SATA link up 1.5 Gbps (SStatus 113 SControl 310)

To map an ata number to the actual sdX device:

ls -l /sys/class/ata_device/ata9/device/host*/target*/*/block

This shows which sdX corresponds to ata9. Che[……]

Read more

Convert Squid/timestamps to a human readable format

Somebody had the brilliant idea of using Unix timestamps in Squid log files. It makes parsing easy but reading them is not so human-friendly.

This is an elegant way of solving the problem:

cat /var/log/squid/access.log | perl -p -e 's/^([0-9]*)/"[" . localtime($1) . "]"/e'

The Perl one-liner captu[……]

Read more

bash – remove first line with tail and last line with head

Say you have a file called test.txt:

line 1
line 2
line 3

Remove the first line:

tail -n +2 test.txt

Remove the last line:

head -n -1 test.txt

Remove both:

tail -n +2 test.txt | head -n -1

Simple, portable, works on any Unix system.

Enjoy!

[……]

Read more

sed – match and replace BIND/DNS serial number programmatically

I had to make modifications to several BIND zone files. Sed proved itself invaluable once again.

The zone files looked like this:

domain.com. IN SOA ns1.domain.com. postmaster.domain.com. (
               2015021001   ; Serial
               600          ; Refresh (10 minutes)
               1800[......]

Read more

Remove all non-ascii characters with perl

Sometimes when creating one-liners, the source contains non-ASCII characters that make parsing harder. To strip them all out, use Perl:

cat dirty-source.txt | perl -pe 's/[^[:ascii:]]//g' > clean-output.txt

This replaces every character that is not in the ASCII set with nothing, leaving only clean[……]

Read more