Work

You are currently browsing the archive for the Work category.

I use a lot of xterms – dozens of them, each one runs an ssh session. When I first started working for The Written Word, Inc. I used to start each xterm, manually place it on the screen on the desktop I wanted it on, type ‘exec ssh <host>‘ in each one, and start/resume a screen session. Whenever the connection dropped, I had to do it all over again. What a pain. So I scripted part of it.

The first thing I scripted was starting all those xterms and running exec ssh in each. If you start an xterm with the -ls argument, it starts a login shell in the terminal. So your login scripts will get run. Using this idea, I edited my login script (~/.bash_profile) and appended:

if test -n "${_SSH_HOST}"; then
exec ssh ${_SSH_HOST}
fi

Then I wrote a quickie “commute” script:

#!/bin/bash
: ${_SSH_HOSTS="every host that I wanted to connect to"}
for _SSH_HOST in ${_SSH_HOSTS}; do
export _SSH_HOST
xterm +sb -ls -geometry 79x25 -title $_SSH_HOST &
done

This script starts xterms with no scrollbar, running a login shell, 79 columns, 25 rows, and sets the window title to the host that the login script will exec ssh to. The strange geometry for the xterms is so that I can fit 12 terminals per virtual desktop. Using a more standard geometry would only allow 9, with a lot of unused space.

So things were improved, now I only had to manually place each xterm, and start the screen sessions in each one. For a little while I was ok, but then I thought to eliminate the manual screen session starting. Using expect I was able to easily record these actions, and edit the generated script. Now all I had to do in the event of a network timeout, or reboot etc was to manually place all these xterms in the correct location, on the correct desktop.

Of course, I wasn’t happy with that either, so I changed the -geometry argument to xterm to note the screen location. With each xterm being 479×349 pixels, it was easy to calculate where I wanted the next terminal to go. I had had to put in several “sleep” statements in my script previously to allow time for the terminals to actually appear on the screen etc. and some of these had to stay, but now all that was required to do manually was wait for the desktop to fill up with xterms, and click the mouse wheel to move to the next virtual desktop 4 or 5 times. Easy! :)

Last week, a switch decided it was time to die, dropping connections a couple of times a day, which meant I had connectivity problems for a couple of days until I discovered that it was the switch that was the problem and not the new router as I had assumed. This meant that I had to do the mouse wheel click to new desktop procedure 4 or 5 times over the course of two days. Doing it once a month or so was an acceptable imposition, but now it was again a pain.

At first, I installed the python bindings for libwnck and attempted to script the xterm window placement, however, I failed to get anything working as quickly as I had expected (would have been easier if I had found wnck_example.py). Another quick google search led me to devilspie. This seemed perfect. Now, at the beginning of my commute script, I generate a devilspie config file:

# Initialize variables
_workspace=2
_col=0
_row=0
# Create new empty config file
:> /home/pogma/pies
# populate config file
for _SSH_HOST in ${_SSH_HOSTS}; do
 echo "(if (matches (window_name) \"${_SSH_HOST}\")\
 (begin (geometry \"479x329+$((480*_row))+$((350*_col))\")\
 (set_workspace ${_workspace})))" >>/home/pogma/pies
 _col=$((_col+1))
 if test ${_col} -gt 2; then
   _col=0
   _row=$((_row+1))
 fi
 if test ${_row} -gt 3; then
   _row=0;
   _workspace=$((_workspace+1))
 fi
done
devilspie /home/pogma/pies >/dev/null 2>&1 &
# We'll kill devilspie later
_pid=$!
...
[snip rest of file to start xterms, start/resume screen sessions etc]

The geometry is a little odd because the window height does not include the title bar. Now, I can start my dozens of xterms, ssh to all those hosts, start the screen sessions if necessary, place the xterms properly, all with one script.

I got a commit bit for the gcc subversion repository yesterday, and exercised it for the first time today with this commit. Even though the number of patches that we have for gcc is very small, doing the commit beats heck out of begging on the mailing list for someone to commit for us :-)

Finding time

I’m working full time hours for The Written Word, Inc. since last week. Of course, I’m remote, so I have to get up in the morning and get myself into the home office, then work for 8 hours or more. Getting up and into the office is not so hard, but I have been getting out of bed a bit too late, starting work at 9am is not early enough, should be at it by 8 if I want to finish at a reasonable time.

Another problem is of course, slacking. I can not report time spent reading slashdot or RangerRick’s Blog or time spend reading/responding to personal mail or slacking on irc as hours worked. Well, I could, I suppose, but I’m a bit too honest to do that. So got to give up on those persuits until evening :)

Tomorrow, will try and start at 8:30! Wish me luck.

Update: Well, did a little better, made it for 8:45.