Monday, January 28, 2013

Word games, part two

Sometimes I wake up in the morning, and manage to get back to sleep. Other times, my brain starts ticking over, and there's no point shouting at it to go back to sleep. This morning was an example of the latter.

Specifically, I started trying to work out the nine-letter word from the Sunday Age, from memory. From there, I started thinking about this earlier bit of hackery, and how I really should have tried to solve the problem properly. So I came up with this:

#!/usr/bin/perl

my $DICT="/etc/dictionaries-common/words";
my $WORD=shift();

my $LC_WORD=lc($WORD);
my $SORTED_WORD=(join '', sort { $a cmp $b } split(//, $LC_WORD));
my $LENGTH=length($SORTED_WORD);

open FILE, $DICT or die $!;

while(<FILE>) {
        chomp;
        $CANDIDATE=(join '', sort { $a cmp $b } split(//, lc($_) ));
        next if (length($CANDIDATE) ne $LENGTH);
        print ("FOUND: $_\n") if($CANDIDATE eq $SORTED_WORD);
}

close FILE;
exit 0;


Perl is definitely not my favourite language (too many magic variables for my liking!) but it's quick, and it works.

Of course, plenty of other people have already solved this issue (and gone well beyond too, in this case) but that's not the point - it was an interesting exercise. My wife did ask "isn't that cheating?" but I kinda think if you write a program to solve the problem, it's arguable not really cheating. Right?

Friday, January 11, 2013

Radio scanners

In a diversion from the usual nerdy stuff, let's talk about radio scanners. Um, well maybe not a complete diversion, but it's not strictly a computer, so you see what I'm saying...

We live in a high fire danger area. The CFA website, fire ready app, ABC news radio... they're all good, but the information is not always timely, and there have been cases where they haven't coped under the high load of a high fire danger day. When you really want to know what's happening nearby, the CFA radio communications give you the best picture. Messages between VicFire (the dispatch centre) and the crews on the ground tell you a great deal about what's happening.

Currently we use an analog scanner - a Uniden Bearcat UBC93XLT, which has served us very well. We replaced the stock aerial with a ScanDucky and it's been terrific. Our scanner came from Dick Smith, but they don't list it anymore. They still list the 92 - similar, but without the rechargeable batteries (I always regarded the extra few dollars for the 93 well worth it - the scanner stays attached to the charger in the kitchen, and when we go mobile it's ready to rock). It looks like Dick Smith and (of all places!) OfficeWorks offer what looks like the "small" version of our scanner - this might be a good "for now" analog scanner (note: I haven't tried one of these, but some casual googling indicates this should do roughly what the 93 does - but caveat emptor - don't buy this assuming it will pick up CFA radio based on my non-recommendation - check that it supports the CFA frequencies). Our scanner's limited keypad was cryptic enough that I was forced to read the manual (I know! I hope they don't cancel my nerd badge for reading the manual... it just wasn't intuitive) so don't expect to open the box and use a scanner straight away.

Eventually CFA VicFire channels will go digital. At this stage the project is implementing digital for country areas, with outer metro to follow "eventually". Check which region you're in here. I'm told the fireground channels will stay on analog (these are the channels used for communication between the trucks working on the same incident, I can generally hear these if the incident is nearby). Anyhoo, digital: it gives the users the option to encrypt their conversations (as Police channels in metro areas already do) but I have been told by CFA sources that the digital channels will remain unencrypted, meaning we can still listen with our scanners. So I plan to upgrade to the Bearcat Digital 396 XT or similar. I assume that it will also receive the analog transmissions (needed for fireground channels) but please note that I cannot confirm this until I have one in my hot little hands. This guy has lots of useful information about these units. If it supports analog, we may have a UBC93XLT for sale... if not, we'll hang on to it.

Saturday, November 10, 2012

Word games

So The Age publishes a word game - Target - in the weekend paper. The rules are simple: you get 9 letters, and have to make as many words of 4 letters or more out of them, and there is one of the letters which must be included in all words. You also have to figure out what the original 9-letter word was which got scrambled up to provide the 9 letters. I quite like the challenge of making words out of the letters, but I rarely figure out the 9-letter word. It frustrates me. In fact, so much that I seem to spend more time figuring out ways to write a program to solve it for me. Yeah, really.

Anyway, I couldn't be bothered doing it "properly" so I decided to do a quick command-line hack to solve it. Today's quiz had the letters H K I A R T B R M Witness the following ugliness:



grep  '^.........$' /usr/share/dict/words|grep 'k'|grep 'r'|grep 'm'| grep 'h' |grep -E '[i]{1}'|grep -E '[a]+'|grep -v '[eou]'

There must be more elegant ways to achieve this, but still, it got the job done in a couple of minutes.

Oh, and the word was "birthmark" in case you wondered :-)

Edit: I solved this properly in perl today.

Monday, September 10, 2012

NanoBSD 6.3 to 8.0 - what do I need to change?

Upgrading some NanoBSD boxes from FreeBSD 6.3 to 8.0, and adding BGP functionality along the way. A couple of config changes that are required:

Enable BGP

  1. add /cfg/local/bgpd.conf and edit to suit (hint: AS and IP addresses ought to match what is assigned for the site)
  2. add  openbgpd_enable="YES" to /cfg/rc.conf
  3. add _bgpd user account to /etc/passwd and /etc/group like this:

pw useradd "_bgpd" -u 130 -c "BGP Daemon" -d /var/empty -s /sbin/nologin
mount /cfg
cp /etc/group /cfg
cp /etc/passwd /cfg
cp /etc/pwd.db /cfg
cp /etc/spwd.db /cfg
mount -u -o ro / 

NTPD changes

On boot, ntpd fails to start with errors such as:

Starting ntpd.
ERROR:  only one configfile option allowed
ntpd - NTP daemon program - Ver. 4.2.4p5


In /cfg/rc.conf, change this:

ntpd_enable="YES"
ntpd_flags="-g -p /var/run/ntpd.pid -f /etc/ntpd.drift -c /etc/ntp.conf -t 3"


to this:

ntpd_enable="YES"
ntpd_config="/etc/ntp.conf"      # ntpd(8) configuration file
ntpd_flags="-p /var/run/ntpd.pid -f /etc/ntpd.drift -t 3"

Wireless access point

Change ath0 interface config from this:

ifconfig_ath0="ssid bsdbox media autoselect mode 11g mediaopt hostap up"

... to this...

wlans_ath0="wlan0"
create_args_wlan0="wlanmode hostap"
ifconfig_wlan0="ssid bsdbox media autoselect mode 11g mediaopt hostap up"


Edit /cfg/hostapd.conf and change interface=ath0 to interface=wlan0

Edit /cfg/rc.conf and change the bridge members so that ath0 is removed, and wlan0 added

Other stuff

  1. add "kern.maxfilesperproc=4096" to /cfg/sysctl.conf so that newer version of bind can start
Also, you can ignore all this stuff in dmesg:
FAILURE - READ_DMA status=51 error=10 LBA=15625215
ad0: FAILURE - READ_DMA status=51 error=10 LBA=15625215


Apparently it's just FreeBSD's way to tell you to relax and have fun :-) PfSense info on it over here

You can also relax about this error:
Starting named.
named[1302]: the working directory is not writable

That's because at boot, /etc/namedb/ isn't writable, but it becomes so when the mfs (RAM disk ) is mounted there. I think...

DMA and Ultra DMA

Transcend UDMA 16GB CF cards do not work reliably - they will not boot on power-up (this is in a Soekris net5501). I can get them to boot by letting boot fail, drop into COMBios over serial, issue a reboot, then and only then will it boot. I suspect this is related to DMA levels supported by the net5501. Obviously not reliable enough for our purposes, so I have ordered some DMA66 SanDisk 4GB cards.

Monday, July 9, 2012

FreeBSD: show outgoing SMTP connections

To show active NAT sessions: pfctl -s state
To show just those going to SMTP ports: pfctl -s state | awk '$7 ~ /:25$/'

Helpful to find outgoing NAT sessions that might be caused by a spambot like, oh, let's say maybe cutwail.

And to show all SMTP sessions, both directions:
 pfctl -s state | awk '$7 ~ /:25$/||$3 ~ /:25$/'

Tuesday, May 29, 2012

Install as another (administrative) user on Windows XP

Gotta love it when you get an install package as an .exe file - right click and "Run As" to install it as an admin account. All good. But when you get an .msi do you really have to log out, then log in as an administrative user, just to install it? I've always known there must be a better way to do it, but it finally irritated me enough to find out. The trick is to use the runas command:

C:\Documents and Settings\myUser>runas /user:domain\admin-account "msiexec /i \"C:\Documents and Settings\myUser\My Documents\Downloads\someInstaller.msi\""

Some gotchas:
  • you must include the whole command you're passing to runas in quotes
  • if the path to the MSI file has spaces in it, you must put it in quotes
  • you can't nest quotes, so you'll have to use a backslash to escape the inner set of quotes
For the record, some bright sparks have suggested some simple reg hacking to create an "Install as" menu item in the right-click context menu. Nice idea, and it appeals to my sense of order and neatness. I'll have to try that next time it irritates me enough.

Thursday, April 19, 2012

Nagios UPTIME errors for a Windows 2003 client

We have a Windows 2003 server - one of a farm of 5 similar machines - that suddenly started reporting errors in Nagios:

nagios# /usr/local/libexec/nagios/check_nt -H mq-citrix-5 -v UPTIME 
NSClient - ERROR: Could not get value

Looks like the issue was with the underlying Windows counters that nagios client uses to get this info - this was useful reading: http://nsclient.org/nscp/discussion/message/1066

So I did this to verify we had the same issue:

cd "\Program Files\NSClient++ "
nsclient++.exe /test 
(error output) 

To fix (on w2k3) we need to force a counter rebuild:

cd \windows\system32 
lodctr /R 

I had to re-start the NSClient++ service, then test again from nagios:

nagios# /usr/local/libexec/nagios/check_nt -H mq-citrix-5 -v UPTIME 
System Uptime - 0 day(s) 9 hour(s) 7 minute(s) 

And we are happy again. In hindsight, I guess this server crashing 6 times in an hour must have corrupted the counters. Wait a couple of minutes, and this hits my inbox:

** RECOVERY alert - mq-citrix-5/UPTIME is OK **

Yay!