Exclusive locks in Bourne shell scripts

Been writing some stuff in shell that needs to be able to ensure it doesn’t start itself twice, so a bit of Googling for exclusive locks in shell scripts brought me to this page on “advanced shell scripting” which had something that looked good.

Problem is that when you put it into a script you’ll find it doesn’t actually work because of some trivial coding issues.

So here’s the fixed version of that function..

# Function to do atomic locking.
# Original found at http://members.toast.net/art.ross/rute/node24.html
# Fixed by Chris Samuel http://www.csamuel.org/

function my_lockfile ()
 {
         TEMPFILE="$1.$$"
         LOCKFILE="$1.lock"
         ( echo $$ > $TEMPFILE ) >& /dev/null || (
                 echo "You don't have permission to access `dirname $TEMPFILE`"
                 return 1
         )
         ln $TEMPFILE $LOCKFILE >& /dev/null && {
                 rm -f $TEMPFILE
                 return 0
         }
         kill -0 `cat $LOCKFILE` >& /dev/null && {
                 rm -f $TEMPFILE
                 return 1
         }
         echo "Removing stale lock file"
         rm -f $LOCKFILE
         ln $TEMPFILE $LOCKFILE >& /dev/null && {
                 rm -f $TEMPFILE
                 return 0
         }
         rm -f $TEMPFILE
         return 1
 }

Structured Blogging : New WordPress Plugin

Just installed the Structured Blogging plugin for WordPress (version v1.0pre13) which provides hidden, machine readable metadata for certain type of blog posts (like film reviews) as well as the usual human readable content. Say “hello” to the Semantic Web folks..

As a test I’ve re-published my review of Kenny, below (original here), with it as a comparison, got to say it makes it look quite professional!

Typo3, htmlcssstyling and spacers

Note to self for next time I can’t remember how to get spacers to work in Typo3 menus when using the htmlcssstyling front end extension..

Need to edit typo3conf/ext/htmlcssstyling/static/setup.txt and add to each of the menu sections:

# Activate Spacer
SPC = 1
SPC.doNotShowLink = 0
SPC.doNotLinkIt = 1
SPC.allWrap =

|

It doesn’t seem to work if you add it into the TS setup sections of the templates. To be fair it does say in the docs that:

Spacer’ is only meaningfull if your frontend navigation is programmed to use it. In this case it does not represent a page with content but is intended to be a non-clickable placeholder in the navigation.

Which, presumably, is precisely what the above code is doing in that setup.txt file.

Further continued adventures with WordPress

Fun fun fun! Now integrated more plugins for various bits of neatness such as the WordPress Gallery2 Plugin that lets me both integrate my gallery2 installation into WordPress and to easily put piccies from Gallery2 into blog postings – like this..

Chris and Donna (taken by Donna!)

Neat eh ? :-)   It’s also doing the random image in the sidebar on the right..

I’ve also been playing around with another of Rich’s plugins – this time for the automatic generation of Technorati tags so this is a bit of a test to see if it’ll do what it says on the can..

RSS issues

Sorry to those tracking this site via RSS that may have seen odd behaviour recently – an artifact of importing all the old stories from Postnuke into WP2 is that the guid’s for the stories weren’t created properly and that was causing a non-compliant RSS2 feed, so I switched to RSS1.

Then I discovered that I could limit the RSS feed to just the last 5 articles (being the ones authored directly in WP2) and that fixed the validation of the RSS2 feed so now I’m switching back!

Shot in the foot by anti-referrer spam measures..

In a word, d’oh!

Spent a while trying to work out why I could install the Google Analyticator plugin but then when I tried to customise it from its option page, or go to any other link on my site from it I got a 403 Forbidden error. Looking at the Apache logs didn’t give much help, it was just whinging about client denied by server configuration and I was completely stumped, so I thought it must be some weird bug and installed Rich’s Analytics plugin, but that had the same problem!

But the fact that two plugins with similar names had the problem, whereas others were finally caused the penny to drop – I had installed a whole bunch of .htaccess to prevent comment spammers from getting too many links in and if they match they return with a 403 error. Turns out that one of them was broken and matching on the “anal” in Analytics!

Sigh.. at least it works now!

Conversion to WordPress complete

Well after many years of running PostNuke I’ve now switched to using WordPress and imported all my Postnuke stories into this (with a bit of hacking). It’s by no means finished, there’s a few more modules to install but mainly for backend stuff rather than frontend.

Still, I’m quite impressed by what I’ve seen of it so far!

DigiKam Rocks!

For about a week or so now I’ve been hunting down and importing all my digital photos I can still get my hands on and importing them into DigiKam. I’ve got to say I’m very impressed with it, I added the current version (0.80) via Achim Bohnet’s apt repository for KUbuntu (recommended by the digikam folks) and it’s just blown me away.

Hierarchical albums are no problem, as is batch renaming (with easily customisable formatting), RAW image conversion (using dcraw), transformations and even a really nifty fuzzy-match duplicate finder!

But the two most useful features are (for me) tagging and the automatic calendar of photographs.

Tagging allows you to have a hierarchy of tags, you get 3 starters of Events, People and Places but then it’s dead easy to create tags below those, and then more below them, and so on. So, for instance, one particular hierarchy goes Places->Australia->VIC->Melbourne->VPAC. When (in tag view) you click on a tag at a certain level you will see photos from that tag and any tags that are children of it, so in the example if I click on the VIC tag I get any photos tagged just as Victoria, as well as those tagged as VPAC, Melbourne or anywhere else below that point.

The automatic calendar of photos is just that, as you import photos the date associated with them is used to create entries in a calendar. By clicking on a particular month you’ll see all photos taken then, and individual days with photos are highlighted in bold. Clicking a day will show the photos from that particular day.

Helpful hint: Importing photos into DigiKam works best when you’ve got the EXIF “DateTimeOriginal” set to the time the photo was taken. Most modern digital cameras will do this for you, but if they don’t you can use tools such as ExifTool (a Perl program) to insert such data. DigiKam will also allow you to add/subtract years, months. days, hours, minutes and seconds from a selection of photos too.

Talking to a mobile from Linux

Fab – just figured out how to talk to my Motorola V525 from Linux.

The standard KDE bluetooth tools sort of work, but the v525 is notorious for not quite doing bluetooth correctly, and so whilst I could pair with the phone and do some rudimentary browsing of the services the phone offered I couldn’t get access to the address book or SMS messages.

So I went digging around and found KMobileTools which, after a bit of faffing about, worked!

The faffing about that was necessary was:

  • Rebuilding the source deb package for Ubuntu Breezy with KDE 3.5 RC1 (their package is built against Debian Sid)
  • sudo mknod /dev/rfcomm0 c 216 0
  • sudo ln -s /dev/rfcomm0 /dev/mobile
  • Find the MAC address of the phone by doing hcitool scan
  • Bind the phone to the device with sudo rfcomm bind 0 [mac-address]
  • Run kmobiletools

As people have pointed out, this would be so much easier with a wizard such as the one provided by K3B to configure CD/DVD burners, but given the software is at 0.4.3.1 it’s pretty amazing!

So far I can access my phone directory, dial/answer/hang-up voice calls and send/receive/save text SMS’s (interestingly a PXT looks like a pathname on a server somewhere). There’s no access to files, but the developer is looking interestedly at the Motorola 4 Linux project which is aiming for remote filesystem access to Motorola phones.