Randoword.sh
I’ve had variations of this script kicking around in my .bash_history for quite some time now. The first version of it merely printed a random word from my dictionary file at a rate of one per second. This served as a source of inspiration/entropy for irc conversations and Flickr titles. Today, I decided to extend this one-liner to generate eight-words-at-a-time at a variable rate and jigger the output into an irssi process to amuse the good netizens. Here is the implementation for randoword.sh.
#!/bin/sh
i=0
while true; do
let i=$i+1
dictionary="/usr/share/dict/linux.words"
dl=($(wc -l $dictionary))
echo -n "randowords #$i: "
for j in $( seq 1 8 ); do
head -n$(($(head -c4 /dev/urandom | od -An -tu4) % $dl))\
$dictionary| tail -n1
done | xargs
sleep $((RANDOM % 3600))
done
Update: I never really understood how to use random numbers within a bash script without invoking perl (or equivalent). In light of _fool’s comment, I rewrote my script using only bash and POSIX commands. I had to break-out /dev/urandom and od because bash’s $RANDOM variable only produces random values up to 32767. Technically, it’d be a whole lot faster for a C program to use a pointer to jump around randomly in the dictionary, but that seems too much like work.
Update 2: The seq command probably isn’t POSIX.
Update 3: In Ruby: ruby -e ' $w=STDIN.readlines; 8.times{print "#{$w[rand(483523)].chomp} "}’ < /usr/share/dict/linux.words
Breaking the Law (of Hostname Canonicalization)
Mailman is a great little program written in Python that lets you manage mailing lists. I was tasked with installing it on a new machine last week, and I got to learn about canonicalization the hard way. All of the emails sent by our server out to the mailing lists were using the host name instead of the DNS A record for the Mailman VirtualHost. I tried for days to fix this and eventually got the feeling that it was DNS related. However, I still couldn’t see why Sendmail would force the To-header back to the canonical name when Mailman was setting it correctly.
Eventually, I happened across this email on Mailman’s dev list that solved the problem by removing one of sendmail.cf’s canonicalization rules. I’m sure this violates some RFC. Although, the hack does indeed solve the problem. The actual wizardry was to comment out the following line in sendmail.cf.
# pass to name server to make hostname canonical # R$* $| $* < @ $* > $* $: $2 < @ $[ $3 $] > $4
It’s absolutely wrong to do this because if you edit sendmail.mc, and restart sendmail, the cf file gets regenerated automatically which obliterates the change. Is there a better way to fix this without violating RFCs and changing sendmail rulesets? Note: I don’t have access to the DNS server.
Pathmunge
This one came from reading RHEL4U3’s default /etc/profile today. Before you call me a nerd and go back to your so called life, hear me out on this. So, the good folks in Raleigh decided to add a function called pathmunge to their default profile. This function just allows you to type stuff like pathmunge ~/bin after to add a directory to your search path. Most self-respecting nerds probably sorted this out in 1987, however, I’m an idiot and continue to do things the old fashioned way until I’m bludgeoned with the technology stick. Unfortunately, pathmunge doesn’t get added to the default shell environment for all users. So, I just added it to /etc/bashrc on my machines today. Here is how to implement pathmunge in all of its glory…
pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}
Feel free to throw this into your ~/.bashrc if you haven’t implemented it already.
rm -blah
Being the resident Unix nerd in my group, about once a year, someone asks me “How do I remove file named -blah”. The problem arises because the hyphen character is the option delimiter for the shell commands. So, typing “rm -blah” or even “rm \-blah” usually results in “rm: Not a recognized flag: b” on most systems. The solution to this problem is so amazingly stupid that the asker usually walks away with his or her pride obliterated. The answer? rm ./-blah. Ivo told me about the alternate solution of using rm — -blah to do it. I like the ./ way better though because it’s so obvious once you know it. I think Jerome might know a better way though.
Purejpeg
Hmmmm… I tried using Purejpeg to remove EXIF and Application Metadata for all JPEG images on involution.com. It had the following effect:
jperrie@homestar ~ $ du -ksH images images2 93MB images 92MB images2
It didn’t matter all that much for me, however, I have used Jpegoptim already on most of the JPEGs on my site. JpegOptim doesn’t catch some of the application data apparently, but it is way cooler in that it runs on *nix.
Distjournal?
There’s been some initial churn about using some or none of involution.com’s SQL rendering php as part of a new project called distjournal. I did finally put together a source package for my site, but it’s not ready for public use yet. I will post the back-end code under some-type of open source license very soon though.
x2vnc problems
I’ve been using x2vnc to navigate between my Linux workstation and Windows laptop.
If you’re not familiar with the software, it basically works like this. X2vnc will let you use two screens on two different computers as if they were connected to the same computer. Even if one of the computers runs Windows 95/98/NT and the other one runs Linux/X11. There were two minor annoyances with x2vnc though. The first problem was that when I unhooked my laptop from the port replicator and the network, I had to restart x2vnc at the command-line. That problem I instantly solved with my mighty script, x2vnc_restart. The other problem, which was more difficult, was that the Windows and Windows Properties key seemed to have no effect on my Windows laptop. I set out to solve that problem today using xmodmap and vnc foo. The first thing I did was to setup the Windows keys in xmodmap by using the following .xmodmaprc. In the X11 world, the right and left Windows keys are modifiers named Super_R and Super_L respectively while the Windows Properties key is Hyper_R. You can see the key code for these by running the xev utility and dutifully pressing each of the buttons. Even after performing the xmodmap foo, my Windows keys were as useful as a whistle on a plow e.g. they still didn’t work. So, after upgrading x2vnc and TightVNC on Windows didn’t work, I tried using RealVNC (another VNC Client/Server install). After that, the Windows keys work as expected. See, it’s just that easy to setup a cross-platform development environment. ;-)
Even More Gnu Screen Foo
![]() |
Well, I managed to further hack my .screenrc to display and IBM stock quote, and a disk space usage monitor. The IBM stock quote script was fairly trivial using wget and cut:
wget -O- http://finance.yahoo.com/d/quotes.csv?s=IBM\&f=sl 2>/dev/null | cut -d ',' -f 2 |
Wormulan on Screen
![]() |
As part of my three part exclusive series on stupid things to do with gnu screen, I discovered backtick support. On the bottom are temperatures for Austin, TX, Bellaire, OH, the CPU in my machine, and the motherboard. In addition, I’m running Wormulan, a network speed monitor (similar to the Gnome Netspeed Applet). |
Gnu Screen per Window BashFoo
I was wondering out loud on the Gnu Screen mailing list today about whether or not it can support per screen .bashrc. The answer was, yes it can do! The winning answer came from Mikael Schonenberg, who unwaveringly opined:
However, when it comes to sourcing different .bashrc files, having a very simple test in your .bashrc making use of the WINDOW environment variable will probably do the trick:
if [ -e $HOME/.bashrc_$WINDOW ]; then . $HOME/.bashrc_$WINDOW else . $HOME/.bashrc_default fi
Mike is apparently the expert on the Gnu Screen “hardstatus line” as well. I’m looking for some way to do custom hardstatus lines per screen which apparently doesn’t exist quite yet.







