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!
- Log in to the My Book admin web app.
- Go to the Advanced section.
- Tick to enable SSH access at the top of the page (note: you may need to update your firmware to get this option).
- 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.
- 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.
- Create a job that touches /tmp/crontab.test every minute (for testing).
echo "* * * * * touch /tmp/crontab.test" > /etc/crontabs/root
- 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
- 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:
/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 ;(