Cron not running straight after reload

I just noticed that if you update a cron job, and then set it to run in the next minute, it won’t work. Basically if a cron file has been updated, then the crond will reload it when it runs on the minute. The problem is that it reloads the file before it can see the new changes, and by the time the reload has finished, it is no longer on the minute and so the command won’t run. Anyway, to cut a long story short, if you are having problems with a cron command not running on the next minute after an update, then try setting 2 minutes ahead instead of one!

How to stop junk (snail) mail

If you are concerned at the level of junk mail you receive through your door that goes straight into the bin (and at the number of trees who lose their lives in the process), then you can opt-out of anonymous mail by contacting Royal Mail, and general junk mail by contacting the Mail Preference Service.
Unaddressed mail

Opt-Outs, 
Royal Mail, 
Kingsmead House, 
Oxpens Road, 
Oxford, 
OX1 1RX

Addressed mail

Mail Preference Service (MPS), 
Freepost 29, 
LON 20771, 
London, 
W1E 0ZT or call 0845 703 4599

SHOW GRANTS for all users on MySQL

Although there isn’t yet a command (that I am aware of) to show all user GRANTS in MySQL, you can write a quick bash script to do the job if you have shell access:

#!/bin/bash
tmp=/tmp/showgrant$$
mysql --batch --skip-column-names -e "SELECT user, host FROM user" mysql > $tmp
cat $tmp | while read user host
do
echo "# $user @ $host"
mysql --batch --skip-column-names -e"SHOW GRANTS FOR '$user'@'$host'"
done
rm $tmp

Job Centre Plus in a nice format

As an employer, I have found the UK’s national Job Centre to be totally underated. It offers a fantastic service that is completely free for employers to list on, but unfortunately there is a stigma attached to the job centre; that it is was once known as the Dole Office and it has since struggled to shed this image.

Despite this, we have successfully recruited many talented web developers from the Job Centre, and so I’m proud to say that our new site is embracing the Job Centre’s content and making it searchable and browseable in a Web 2.0 format. Hopefully this may help to encourage more high-tech and skilled professional employers to list on the site.

Fixing MySQL Replication with duplicate key error

Today our MySQL Master tracking db went down (due to host server crashing) which consequently screwed up the slave. Here are the steps I took to fix it.
Firstly, check the slave status with:

 show slave status\G;

If the slave is reporting something like ”Last_Error: Error Duplicate entry replication”, this can be fixed by the following:

 stop slave;
 set global sql_slave_skip_counter=1;
 start slave;
 show slave status\G;

It will take some time after issuing those commands for the slave to rebuild itself from the master, but you can check the progress by querying the db to see what record we are up to, for example:

 connect trackdb;
 SELECT * FROM `track` WHERE 1 ORDER BY id DESC LIMIT 10;

Strange php problem where session_start hangs

We encountered a very strange problem in the office today where PHP’s session_start() function would appear to randomly hang. In the end the problem turned out to be that if you start a session on one script and then that script never completes executing, it will lock the session. So if you try to access the same session from a different script, your script will appear freeze indefinitely.

Ubuntu Dapper on a Fujitsu Siemens Amilo 7400 laptop

My friend recently asked me to reinstall his Amilo 7400 laptop as it was covered in spyware. So I thought I would take the opportunity to convert him to Linux by installing Ubuntu. At the time, Breezy Badger was the latest release, and after hours of fiddling trying to get his centrino wireless interface to work, I decided that the process of connecting to wireless networks was just too complicated on Linux for a novice user, and so I gave up.

A couple of months passed and when Dapper Drake was released, I heard that there was now a graphical network manager for gnome that could handle wpa encrypted wireless networks, so I thought I would give it another shot.

All I can say is, what an improvement! I still had to do a bit of fiddling to get the software switch for the wireless card to come on automatically, but I’m now confident that he will be able to use the gnome network manager to connect to wireless networks easily.

Here’s the steps I took to get it all working: First, to get the software wireless radio switch to come on, you need to load a kernel module:

 modprobe fsam7400 radio=1

Once this is loaded, you can test it works by running a wireless network scan

 iwlist scan

To get the kernel module loading on start up you need to add it to /etc/modules

 vim /etc/modules
 fsam7400 radio=1

You then need to install the gnome-network-manager package.

 sudo apt-get update
 sudo apt-get install network-manager-gnome

And that’s basically it! I then proceeded to add other useful applications (thunberbird, realplayer, amsn etc..) using Automatix which installs everything for you.