Tag Archives: mac osx

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