Category Archives: Linux

Tips and stuff

Need to delete old emails – archivemail to the rescue

I have a few customers who have massive Spam traps and Catch-all email accounts.  These accumulate an enormous amount of email, and like any good tree need to be pruned.

I was going to write a small PHP script, or some crazy sieve scripts but of course someone has been there, done that, and compiled the source already for me.

An easy solution is to use archivemail - http://archivemail.sourceforge.net/

archivemail  --delete --days=60 imaps://spambox:[email protected]/INBOX

 

Archivemail will let you delete emails older than a date or time and works with IMAP, POP3, etc

HowTo add a USB device permanently with VirtualBox 3.0+

So I was having a little trouble adding a USB device permanently to a Virtual Machine guest with VirtualBox. The trick is to use the VBoxManage command to add a USB filter into the Machine’s configuration which will automagically attach whenever the VM is run.

First, find a list of all usb devices on the host, remembering to run these commands as the user your VirtualBox machine is under. In this example we’ll be using a Canon MX7600 printer as a test USB device.

$ VBoxManage list usbhost

UUID:               6bac41f4-cc44-40e4-a726-4d9655a49f63
VendorId:           0x04a9 (04A9)
ProductId:          0x171c (171C)
Revision:           1.3 (0103)
Manufacturer:       Canon
Product:            MX7600 series
SerialNumber:       102787
Address:            /proc/bus/usb/007/004
Current State:      Captured

Now we use the details of the USB device to filter adding into our VirtualBox machine. In this case our VirtualMachine name is winxp.

The usbfilter command requires four options at a minimum.

VBoxManage usbfilter        add
--target ||global
--name
--action ignore|hold (global filters only)
[--active yes|no] (yes)
[--vendorid ] (null)
[--productid ] (null)
[--revision ] (null)
[--manufacturer ] (null)
[--product ] (null)
[--remote yes|no] (null, VM filters only)
[--serialnumber ] (null)
[--maskedinterfaces ]

So armed with this info let’s add our device.

VBoxManage usbfilter add 0 –target winxp –name canonmx7600 –action hold –active yes –vendorid 04A9 –productid 171C –revision 0103 –manufacturer Canon –product “MX7600 series” –serialnumber 102787

Drupal – “Content (missing)”

I’ve started playing with Drupal and looking at moving a few sites over to it. In a late night session of bolting things together I ran into a bit of a snag with a few modules trying to create thumbnails on teaser articles.

Unfortunately when I installed the imagefield CCK module I ran into a snag where it wouldn’t allow me to continue without the ‘content’ module which was missing.

I attempted to search for this missing module in the drupal module downloads section with no luck… http://drupal.org/search/node/type%3Aproject_project+content gave me no joy at all.

Luckily, the a nice Drupal IRC user slapped me with a quick ‘CCK = content’ line after I pleaded where this magical ‘Content’ module is and of course after I installed the CCK module everything worked like a charm. I had thought I had already installed this module and was probably too tired to have checked this first…

So for any newbie Drupal users out there I hope you find this helpful tip on Google before you harass some poor sod on IRC… that way you might actually appear somewhat knowledgeable.

MyBook backups with Rsnapshot and some bash trickey

I had a client accidentally purchase half a dozen 500GB MyBook’s instead of the simpler cheaper USB models.

Since this site is remote from me it took a little while to deduce what was going on since the MyBook’s don’t act as USB drives and hence don’t appear as a USB device to linux.

User: ‘Yes, I’ve plugged it in! Yes it’s using the white cable!’
Me: ‘So… what exactly does it say on the box what drive it is…’

Anyhow, after figuring out that is was a MyBook I implemented ssh access using Martin Hinner’s clever hack and found a nice website of various MyBook Hack’s.

I was originally using the venerable Rdiff-backup, but alas couldn’t see it in the Optware packages. So I implemented a Rsnapshot solution, the only problem was I wanted some notifications from the MyBook devices to check that the backups were working, and so a simple bash script was in order…

#!/bin/bash
mailto=[email protected],[email protected]
time=$1
if /opt/bin/rsnapshot $time > /tmp/rsnapshot.log 2> /tmp/rsnapshot.log
then
subject='Backup success'
else
subject='Backup FAILURE'
fi
cat /tmp/rsnapshot.log | /opt/bin/nail -r [email protected] -s "$subject" $mailto

I hate Nano!

I hate that cursed text editor. This morning I spent 5 minutes trying to figure out why a fresh crontab wasn’t working as I ssh’d into a server… My syntax was correct yet crontab refuse to save my entry stating bad minute errors in crontab file.
I then realised it was the crap characters nano was feeding into the beginning of the file!

A swift export EDITOR=vim and my crontab problems were gone.

Note: After bitching to a friend of mine who is pro Nano he stated to me that nano > 8. My point exactly, he’s so handicapped from using nano that he can’t even type an Asterisk.