Mac OSX – Can’t eject disk (in use)

So you get that annoying “The volume can’t be ejected because it’s currently in use.” message trying to unmount your disk, well, to find out what is using the disk, you can use the lsof command (LiSt Open Files)


Run it as sudo, and you should easily be able to see which application has files open (usually VLC for me)

sudo lsof | grep /Volumes/My_Drive

Obviously substitute My_Drive with the mount name from your machine

svnX – Use DiffMerge as diff tool

So, I use svnX on MacOSX and I find DiffMerge a much nicer application than the default FileMerge, but I couldn’t get it to load. I was getting some spurious error about a missing .sh file:

Can’t find tool ‘’ required to use DiffMerge

Anyway. I found this file in the following folder:


And I simply copied it to a folder within the path env,

cp /Applications/ /usr/local/bin/

Sorted. Don’t forget you actually have to change the application preferences.

Log in to SSH with no password

So you want to have your password remembered by a remote SSH connection?

Easy, following these steps

On your local machine, create a new SSH key:


It will ask you for a file location and a keyphrase, but I always just hit enter three times.

This will create a file in the default folder (or whichever folder you chose in the first step)


The contents of this file want to go into a file on the remote server: If the file doesn’t exist, you’ll have to create it.

/root/.ssh/authorized_keys, or

That’s it. There are some cases where you have to change the permissions of the authorized_keys file but I’ve not had to do that. I think the suggested chmods are 640 and 700, but don’t hold me to that

From now on, you won’t be prompted for your password when SSH’ing in from the local machine. In order to revoke access, delete the right line from the authorized_keys file.

Finding files in Linux/Mac Terminal

Finding files is a little different to MS DOS!

find <startlocation> <type> <filename> <exec>

The exec is a simple way of performing functions on the results. If you leave it off, the find doesn’t really do anything.

So, the simplest thing to do is find a file, so the exec becomes the output:

find / -name wkhtmltopdf* -exec ls -ls {} \;

That will find all files starting with wkhtmltopdf starting from / and the function to run on it is ls -ls {} \;

The {} will be replaced with the search result, so, in essence, ls -ls filename; will show you the details about the file which is what I want, as I am looking for all copies of the wkhtmltopdf toolkit on the server.

You can obviously change the exec to delete the files, or copy/move them, or interrogate further…

Get MAC address from IP address

Had a routing issue the other day, and I was remotely trying to forward a port to a device. I didn’t know the MAC address of the device, and my Home Hub was insisting on that information for the forward destination. I knew the IP address, so there is a simple Windows command to get the MAC address from the IP address:

arp -a <ip_address>


arp -a

Easy. This command works in Windows as well as Linux! Well theres a thing… It also works in Mac, but you drop the -a parameter:


Compile php_imap and mssql for PHP on Mac


To get imap support in PHP on your Mac, you need to get the php_imap module compiled for your version of PHP. I have attached mine to this to save you the effort, but this wiki article can remain for reference.

Firstly, you need to download the Client-c code. This is a library that allows various applications to communicate with IMAP servers. PHP being one of them.

Save it into your downloads folder, and once finished, extract it. If you are using Terminal, you can do the above with the following commands: (NB, do all this in sudo)

cd ~/Downloads
curl -o imap.tar.gz
tar -zxvf imap.tar.gz

Then we need to compile it, and copy all the C files to the right places.

cd imap-2007e/
make osx EXTRACFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
mkdir /usr/local/include
cp c-client/*.h /usr/local/include/
mkdir /usr/local/lib
cp c-client/*.c /usr/local/lib/
cp c-client/c-client.a /usr/local/lib/libc-client.a

Now we need the version of PHP we need. To find out what version you are running, run this in a Terminal window:

php -v

That’ll tell you which version you need. Replace the curl address below with the relavant version from the website.

cd ~/Downloads
curl -o php.tar.gz
tar -zxvf php.tar.gz

Once that is all extracted, we need to compile PHP:

cd php-x.x.x/
sudo ./configure
sudo make

Once that’s done we can go to the imap extension folder and compile that extension. There are more extensions in the file structure, but for now, we just need the imap one:

cd php-x.x.x/ext/imap
CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
./configure --with-imap=/usr/local/imap-2007 --with-kerberos --with-imap-ssl=/usr/

That should create a nice little file in the modules folder:


This file needs copying to the extensions folder on your PC. So you need to find the right folder. Mine was:


So, I copied the file there:

cp /usr/lib/php/extensions/no-debug-non-zts-20090626/

And then all we need to do is edit the php.ini file, to load the extension:

nano /etc/php.ini

Scroll down to the extensions bit, and add it in, mine would be like:


Then reboot Apache

apachectl restart

That should be it.

Next, php_mssql (if required)


The process is really very similar to what we just did for imap, but we do need to install freetds which is a mssql thing

Create the directory /usr/local/freetds
Download the latest version of freetds (
Open a terminal window
Untar/zip the freetds file and cd into that directory in terminal

Run the following to compile the extension

 ./configure --prefix=/usr/local/freetds --sysconfdir=/usr/local/freetds/conf/freetds --disable-libiconv --disable-odbc
sudo make install

Find the PHP source code from earlier, and go to the correct folder:

cd /Users/chris/Downloads/php-x.x.x./ext/mssql/
sudo phpize
sudo ./configure --with-mssql=/usr/local/freetds
sudo make

Now its the same as the imap section. Find the file in the ext/mssql/modules/ and copy it to the extensions folder.

cp /usr/lib/php/extensions/no-debug-non-zts-20090626/

And then all we need to do is edit the php.ini file, to load the extension:

nano /etc/php.ini

Scroll down to the extensions bit, and add it in, mine would be like:


Then reboot Apache

apachectl restart

And that should work now. Create a page with a simple echo phpinfo() and that should confirm the fact.

Where is my.cnf on Mac OSX?

On Mountain Lion, I found that the my.cnf file is missing. This is because Mac uses the default MySQL settings and therefore doesn’t require a config file.

If you want to change the default settings, you’ll need to create a my.cnf in /etc/:

You’ll need to sudo into Terminal, and copy one of the default configs from the MySQL folder to the /etc/ folder:

sudo cp /usr/local/mysql/support.files/my-huge.cnf /etc/my.cnf

Then just use Nano or whatever to update the file, then restart MySQL and you should be good to go with your new settings.

SSH Clears Terminal on disconnection

I found on some servers that when I disconnect from an SSH connection, the terminal console is cleared.

This is very annoying if I have to SCP a file after disconnecting, and I cannot remember the path/filename.

So, on the remote server, check the .bash_logout file in the user’s home folder. This will contain commands to run when that user disconnects, and in this particular case, it had


I commented that out, and we’re sorted. (Mind you, you might want to check with the server administrator before fiddling as it could be a server/company policy)