Random musings of a Geek

Change default browser in Thunderbird on Linux

Go to Edit -> Preferences -> Config Editor

Toggle the values of the following to true:

network.protocol-handler.warn-external.http
network.protocol-handler.warn-external.https

The next time you click on a link in an email Thunderbird will ask you to select a browser to use :)
Yay to Thunderbird for being completely awkward.

MySQL Replication Setup (using dump)

On the master, enable binary logging and set a unique server ID. Each MySQL server being replicated to must have a unique ID also. Modify my.cnf with the following, and restart MySQL.

[mysqld]
log-bin=mysql-bin
server-id=1

On the Slave, edit my.cnf and add a unique server ID for the slave.

[mysqld]
server-id=2

On the master, add a user for replication that has the ‘replication slave’ privilege. This should be a separate user that can only be accessed from specific hosts, for security purposes. More info at http://dev.mysql.com/doc/refman/5.1/en/replication-howto-repuser.html

Get master bin log coordinates and lock tables to prevent changes whilst synching…

Start a session on the master and run:

FLUSH TABLES WITH READ LOCK;

Using a different session, run SHOW MASTER STATUS to get the current bin log file name and position. Note these down as they are used in the ‘CHANGE MASTER TO’ slave statement later.

On the master, dump the database you’re wanting to replicate and scp it to the slave server.

mysql > SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 73 | test | manual,mysql |
+------------------+----------+--------------+------------------+

mysqldump': mysqldump -u root -p TheDb > TheDb.sql
scp TheDb.sql user@server:

On the slave, import the DB dump from the master:

mysql -u dbuser -p < TheDb.sql

After that, run a ‘CHANGE MASTER TO’ statement:

CHANGE MASTER TO
MASTER_HOST='1.2.3.4',
MASTER_USER='replication_user',
MASTER_PASSWORD='********'
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=12345,
MASTER_CONNECT_RETRY=10;


and then start replication with:

START SLAVE;


You should now exit the session on the master that was locking the tables (or use the unlock tables statement).

Replication should now be setup

Repairing GRUB

Here is how to restore your GRUB MBR after installing Windows 7 (or any version for that matter).

  1. Grab a boot CD of Ubuntu and boot it up
  2. Open the terminal
  3. > sudo grub
  4. If you have a none standard installation (multiple installations of linux or weird partition setup) then use:
    > find /boot/grub/stage1 to discover where your root should be
  5. > root (hd0,0)
  6. > setup (hd0)
  7. > quit

reboot :)

I personally have 2 different flavours of linux installed and my root happened to be 0,4 and 1,4 as I have 2 drives and each install was on a different partition of each drive. I would recommend choosing the one that you boot into most frequently – as when you install new Kernels etc via apt it will auto configure GRUB for you.

Batch converting PSD images in linux using ImageMagick

I found myself wanting to batch convert a load of psd files to jpegs today, so I went about looking for a way to do it via the command line.

The tool I chose was Imagemagick. At first I was going to use the tool ‘mogrify’ but it doesnt seem to support the -flatten parameter even though it says it does in the manual… hmmm. The flatten param is needed when converting a psd because of course the psd is multi layer so if you try convert to jpeg without flattening it will generate a jpeg for each layer.

I opted for the standard ‘convert’ command with a little bash magic. The following little script will process all psd files in a folder to jpeg files. You could easily change it to pass in more parameteres etc.

#!/bin/bash

if [ -z “$1″ ]
then
echo “Usage: please specify a base directory”
exit $E_NOARGS
fi for file in $1/*; do
/usr/bin/convert -quality 80 -flatten $file ${file/psd/jpg}
done
Home