21st Century Digital Boy

March 21, 2008

Mac OS X network locations and the command line

Filed under: Apple, Unix — Tags: , , — 21cdb @ 7:24 pm

Problem: I have a bunch of “workflow” wrappers to svn, but I’ve foolishly hardcoded my svn server to svnserver.local, its name on the Bonjour network. So I go home, and on the same laptop I use at work, I have to do 86 extra steps to use my scripts. Wouldn’t it be great if the scripts knew how to figure out if I was at home?

Complication: Airport at home and office are configured essentially identically, so it’s not like I can just look at the IP address.

Solution:scselect! It’s important to note that calling it w/o options prints to STDERR not STDOUT. No idea why.

Anyway after some messing around with things I ended up with this:


scselect 2>&1 | egrep “\*” | tail -1 | awk ‘{print $3}’ | sed -e ’s/(//’ -e ’s/)//’

This returns the current network location. Configure (and switch to) the appropriate network location, and now my wrappers know which repository URL to use. Yay.

Now someone please tell me there’s an easier way ….

February 8, 2008

Lazyweb: Sending Sun Stop-A from a serial console

Filed under: Apple, Tech, Unix — Tags: , , , — 21cdb @ 5:32 pm

So I’m currently connected to a v100 over a serial line to a keyspan USB adapter thingee, and a terminal running `screen /dev/tty.usbserial 9600`. This works swell for talking to Sun boxes, right up until I need to send Stop-A.

Sending ‘break’ (cmd-.) doesn’t work, and I can’t make any of the screen break thingees do much of anything.

Halp?

Update. Apparently the answer is one of:
1. Purchase ZTerm, which is not a Universal Binary and seems like it never will be, or
2. Find a Windows machine that has a proper break key

April 26, 2007

The man page for ‘logrotate’ is full of lies

Filed under: Unix — 21cdb @ 4:20 pm

The man page for ‘logrotate’ is full of lies. What it says is

extension ext
              Log  files  are given the final extension ext after rotation. If
              compression is used, the compression  extension  (normally  .gz)
              appears after ext.

What it means is (courtesy http://www.die.net/doc/linux/man/man8/logrotate.8.html)

extension ext
Log files with ext extension can keep it after the rotation. If compression is used, the compression extension (normally .gz) appears after ext. For example you have a logfile named mylog.foo and want to rotate it to mylog.1.foo.gz instead of mylog.foo.1.gz.

Note the subtle difference, namely, “keep it” versus “given” (passive versus active; the latter implies the file is renamed). This might not apply to anything other then CentOS 3.

April 9, 2007

I don’t understand AF_UNIX

Filed under: Perl, Unix — 21cdb @ 12:06 pm

Using IO::Socket, one can make a Unix domain socket. (Specifically, it’s a SOCK_DGRAM).

Here’s my problem: The protocol requires that you read 2 bytes, which is the length of the message that follows. So I can do read() on 2 bytes, then read() on the remainder of the string.

OK, so what’s the problem? I don’t know what to do next. Further connections fail; it apparently isn’t putting the pointer in the right place (it reads 2 bytes into the string, which is always in the wrong place). shutdown() and close() don’t work, because, the latter closes the connection (no further reads) and the former …. closes the connecton (one cannot un-shutdown).

Am I supposed to open() it again? Wouldn’t that mean I’m open()-ing the socket constantly?

AF_UNIX apparently doesn’t like accept(), so looping over accept() and handing off to a child process, no worky.

Yes, I’ve googled. Everything - everything - points to doing it all by hand, with the low-level socket functions. IO::Socket::UNIX is supposed to make this “easy”. (Also I don’t do much socket programming)

Update. I do not understand why my $client = $server->accept() or die "Can't accept: $!\n"; returns Invalid argument since the man page says the package is optional and the code has 1 or 2 optional arguments, the first of which is the socket itself. I’m just missing some big piece of enlightenment and understanding here.

Blog at WordPress.com.