Tag Archives: mac

Prevent external HDD drives from sleeping on Mac OSX

I have 4TB of data stored in three external hard-drives attached to my mac. It’s very frustrating when these HDDs enter sleep and the operating system hangs until they wake up, even for actions which do not involve them.

So, putting the side-effect of possible sooner failure due to wear aside, I wrote a little bash script to touch a file on every drive and set this script to run every 5 minutes via cron.

I’ll probably optimize it a little by disabling it every day during daytime hours (when I’m not at home).

This is the bash script

for D in /Volumes/*; do
    if [ -d "${D}" ]; then
        echo "${D}"
		touch "${D}/.touchdrive"
    fi
done

And this is the crontab entry for it

*/5 * * * *   sh /touchDrives.sh > /touchDrivesCron.log

 

How to keep alive SSH outbound connections in OS X Terminal.app

If you want to keep alive the ssh connections you’ve open in OS X Terminal.app, you can edit the file on your mac located here: /etc/ssh_config and modify the line where you find this instruction: ServerAliveInterval. That tells the number of seconds at which your computer will send a null packet to the server in order to keep the connection alive.

By default, that line is commented and the value is zero anyway. You should uncomment the line and increase the value to something bigger than zero. I’ve set mine to 5.

You can edit the file directly in terminal, with admin permissions like this:

sudo nano /etc/ssh_config

You’ll be asked to enter your admin password. Find this line (as it is in default config):

#	ServerAliveInterval	0

and delete the hashtag at the beginning of line to uncomment it and change the zero value to something bigger. Ctrl + O to save the file and Ctrl + X to exit the nano editor.