Diary of a geek

August 2005
Mon Tue Wed Thu Fri Sat Sun

Andrew Pollock


Other people's blogs


RSS feed

Contact me

JavaScript required

Wednesday, 24 August 2005

Fun with xargs

Had some fun with xargs this morning. I came up with such a monstrosity, I have to record it for posterity.

The situation was one where we had a script that was scping a whole pile of files around, and the source directory got so big, that a straight "scp ${SOURCE}/* $DESTINATION" was resulting in the good old command-line too long situation.

Sounds like a job for xargs I say. But how do we tack the destination on the end? I'm used to situations where you just want to pass a whole lot of arguments to a command, but not have a constant value on the end. Oh, and this was on Solaris for good measure, so I was fully expecting to not be able to do it.

Did some prototyping. Put "a-z" in /tmp/alphabet, one per line.

apollock@caesar:~$ cat /tmp/alphabet | xargs -L 6 echo
a b c d e f
g h i j k l
m n o p q r
s t u v w x
y z

Right, so that solved the argument length issues, but I needed a constant argument on the end. I tried

apollock@caesar:~$ cat /tmp/alphabet | xargs -L 6 -i echo '{}' foo
a foo
b foo
c foo
d foo
e foo

But as you can see, (and so the manpage says), -i implies -l1 (which is the same as -L 1). Bummer.

So then I came up with this ripper:

apollock@caesar:~$ cat /tmp/alphabet | xargs -L 6 echo | xargs -i echo '{}' foo
a b c d e f foo
g h i j k l foo
m n o p q r foo
s t u v w x foo
y z foo

That's the ticket!

[17:31] [work] [permalink]


One of the things I wanted to do when I first got my PowerBook was connect to the Internet via the GPRS connection of my T630 over Bluetooth. It's always eluded me.

I recently reinstalled my PowerBook because I wanted to reduce the amount of space dedicated to Linux, and generally give it a clean out. Tonight, I was reinstalling bits and pieces and decided to revisit this chestnut again.

After a bit of concerted Googling, I found the homepage of Ross Barkman, who has some useful extra scripts for the T630, which for some reason, Apple doesn't ship with MacOS X. After throwing this into my /Library/Modem Scripts/ directory, and following the detailed instructions included with the scripts, I had things working very nicely indeed via Telstra.

Thanks Ross, I owe you a pint.

[03:51] [tech] [permalink]