Earlier today, a tweet from a colleague got me wondering whether I could set up cron on my NAS drive to give me the ability to run scheduled tasks. I don't leave any machines on at home, but my NAS drive is on 24/7, so it could be useful - especially as a backup system if Google open an API to Takeout!

I managed to get it working with some help from this post, so I thought I blog the details here (it turned out to be simpler than that post suggested) should it be useful to you (or to me, should I ever need to do this again).

There was no requirement to do anything crazy to make this work. I didn't install anything on the NAS, everything was there - even the SSH access is enabled via the web app!

  1. Log in to the My Book admin web app.
  2. Go to the Advanced section.
  3. Tick to enable SSH access at the top of the page (note: you may need to update your firmware to get this option).
  4. SSH into to the IP address of your mybook, using the username "root" and the password displayed on the page where you enabled SSH access.
  5. Create a folder to store our crontabs. Since /var/spool is mapped to /tmp it'll be wiped at rebooted, so we need to keep our own.
    mkdir /etc/crontabs
  6. Create a job that touches /tmp/crontab.test every minute (for testing).
    echo "* * * * * touch /tmp/crontab.test" > /etc/crontabs/root
  7. Create an entry in init.d to start crond using our /etc/crontabs folder.
    echo "/usr/sbin/crond -c /etc/crontabs" > /etc/init.d/S99crond
  8. Set permissions for execution.
    chmod 755 /etc/init.d/S99crond

That was all there was to it. I ran "reboot" and let the NAS reboot, then confirmed that /tmp/crontab.test was being touched every minute (with "ls /tmp/crontab.test -l").

Note: You should disable SSH access when you're done, or change the password. Otherwise, anybody on your network may be able to gain root access to your NAS!

If you make changes, you'll need to restart crond. You can do this with:

killall crond
/usr/sbin/crond -c /etc/crontabs

Next up, I'd like to find a way to edit the cron scripts from my chromebook via something like cloud9ide rather than ssh />Vi ;(