Run task on drive connection or disconnection in Windows

12 July 2012

Description

This script watches for Windows drive letter connection or disconnection events and allows scheduling of tasks to run accordingly. For example, this is useful if you want to run a program to synchronise the contents of a USB pen drive automatically when it is inserted.

Tasks can be configured in a human-readable JSON format configuration file. It installs itself as a service and is very, very alpha.

Requirements

  • The script should work in Python >= 2.6 and requires pywin32.
  • It has been tested on Windows 7 x64 only.

Source code repository: https://github.com/inversion/drive-letter-watcher


Run task on drive connection or disconnection in Windows - Comments

This blogging thing…

1 July 2012

I’ve started blogs in the past, but always abandoned them pretty quickly. Hopefully this one will be more successful since I like the domain name better than usual.

Expect to see programming with smatterings of ranting and musing.

Cheers,

Andrew


This blogging thing… - Comments

Selective Reading WordPress Plugin

1 July 2012

Since I will soon be writing about travel on this blog, which will be unrelated to the rest of the content, I have written a small WordPress plugin that allows visitors to hide categories they do not wish to read from the site. This was a good opportunity to get some experience writing WordPress plugins too, the API is pretty easy to use.

The plugin is currently active on this site as you can see from the show and hide links in the categories sidebar. It works for hierarchical categories too.

The code is available at GitHub along with a list of current and planned features.

See the page in the WordPress plugin directory at https://wordpress.org/extend/plugins/selective-reading/


Selective Reading WordPress Plugin - Comments

Auto-update Ubuntu server with email notifications

25 June 2012

It’s useful to have a script to keep the packages on your server up to date. On the desktop there is a GUI auto-update tool which is active by default. The caveat is that you don’t want updates to break your server without you realising.

This script is adapted slightly from the Ubuntu wiki to do a ‘safe-upgrade’ and to mail directly rather than using an external SMTP server. It also tails the output of the update since it’s pretty long. Use at your own risk etc., script is below. Copy to /etc/cron.weekly and chmod +x.

#!/bin/bash
#
# use aptitude to automatically install updates. log and email any
# changes.
#

#
# variables to change
#

# address to send results to
MAILTO=[email protected]

#
# script is below here (do not change)
#

tmpfile=$(mktemp)

#
# actually run aptitude to do the updates, logging its output
#

echo -e "aptitude update\r\n..." >> ${tmpfile}
aptitude update | tail >> ${tmpfile} 2>&1
echo "" >> ${tmpfile}
echo "aptitude safe-upgrade" >> ${tmpfile}
aptitude -y safe-upgrade >> ${tmpfile} 2>&1
echo "" >> ${tmpfile}
echo "aptitude clean" >> ${tmpfile}
aptitude clean >> ${tmpfile} 2>&1

#
# i get a lot of escaped new lines in my output. so the following
# removes them. this could be greatly improved

tmpfile2=$(mktemp)
cat ${tmpfile} | sed 's/\r\r/\n/g'|sed 's/\r//g' > ${tmpfile2}
mv ${tmpfile2} ${tmpfile}

#
# now send the email (and ignore output)
#
mail -s "Aptitude Upgrade $(date)" ${MAILTO} < ${tmpfile} &> /dev/null

#
# and remove temp files
#

rm -f ${tmpfile}

Auto-update Ubuntu server with email notifications - Comments