Saturday, 26 February 2011

Wednesday, 23 February 2011

Finding the second occurrence of a regexp with sed

This is something that I needed, but couldn't find. So for the benefit of the next person, here's what I did.

I have files that each contain two heredocs, and I needed a simple script to pull out the second one. The files look something like this:


#!/bin/bash

# various commands chomped for simplicity

ftp -n ftp.example.net <<EOT
user uid pwd
type image
get importantfile.tgz
quit
EOT

# lots more code

cat >scriptfile.sh <<EOD
#!/bin/sh
ftp -n ftp.example.net <<EOT
user uid pwd
get file1.sh
get file2.sh
EOT

# more code

EOD

# more code



After some searching and poking around with sed, I came up with this:


sed '1,/<<EOT/d;1,/<<EOT/d;/^EOT$/,$d' $1|ftp -n ftp.example.net


It locates one <<EOT, then locates another, deleting all the while. Then it stops deleting until it finds ^EOT$ and wipes out the rest. There's probably a simpler way to do some of this, but this is what I managed to hack together.

Thursday, 3 February 2011

IPv4 address space depletion: what will it mean?

The Internet has run out of addresses.

Okay, that's not perfectly accurate. What's happened is that, as of Feb 1st, the IANA is down to its last five Class-A address blocks, and according to policy, it must dole them out to five regional registries. So it's all a whole lot of noise in the upper echelons of the internet's organizational structure, and what's it mean for the end user?

In short: Nothing yet. You can ignore this whole issue and keep going as you are for quite a while. Your IP address comes from your ISP, and your ISP gets blocks of addresses from one of the registries, so they'll be alright for a while. How long is anybody's guess though; estimates range from three months to a year or so.

Ultimately, there will come a time when an ISP requests some more addresses and there just aren't any. What happens to their customers then? Various columnists have predicted that ISPs will have to switch to large-scale NAT - doing the same thing at the ISP level that is done at the home level when someone plops a cheap router down and shares their internet connection among multiple users. Effectively, the ISP will sell you half of a shared connection, and it'll be potentially tricky to run a simple home server.

But there's another possibility, and potentially quite scary because you won't know it's happening till it's too late. An ISP might go "on the cheap" and simply not buy enough IP addresses. Its customers wouldn't notice the difference, until some day everyone's online all at once, and your ADSL modem just can't get the information it needs, so it'd simply fail to get you online. You'd reboot your modem a few times, and eventually someone else would have gone offline, and you would get their IP address and be online. Meanwhile they're locked out, waiting for someone else to disconnect... and these days, people leave their internet connections on all the time, unlike in the days of dial-up.

It's time NOW to start talking to ISPs about IPv6. The true solution is to deploy IPv6 and to deploy it now; we need content to be on IPv6 and we need eyeballs to be on IPv6. Inquire about whether your ISP can offer you dual-stack networking - an IPv4 address and a block of IPv6 addresses - and if not, how soon they intend to offer this. It has to happen. It's just a question of how soon, and who is going to be left behind.