Synology DSM 4.0/1 appears to only come with a single crontab file. There is no implementation for a daily cron directory (that I can find).
So I created my own.
- Open /etc/crontab for editing
- Add: “0 1 * * * root for myCsh in `ls /<your directory path>/cron/cron.daily/*.sh`; do $myCsh;done > /dev/null 2>&1
- Don’t forget to put in your real directory path above
- Must use tabs (NOT spaces) between fields.
- Spaces in the final field (that starts with “for myCsh” are OK
- The above has the “for” loop being run every day at 1AM
- Restart cron for changes to take effect
- synoservice –stop crond
- synoservice –start crond
Configure Cron Daily Directories
- These are the directories referenced by the above “for” loop
- Example: /<something>/cron/cron.daily
- cd cron.daily
- Create empty.sh
- Needed so that if no real scripts are in the directory, the cron “for” loop will not throw any errors
- Just having an executable file is enough, it does not even need anything in it
- touch empty.sh
- chmod 755 empty.sh
The cron.daily directory is where I put a script that calls my incremental rsync backup script.
I also created a “cron.test” directory for testing different things. I usually have its line commented out in crontab, but it follows the same concept as above.
When I was creating this, I wanted some reassurance that the crontab was actually working as expected, so I created a simple script that when ran creates another file in the cron.daily directory with a date time of the last run.
- I put the “_” in the name so the file should be the first executed by the “for” loop
#!/bin/sh shDir="$( cd "$( dirname "$0" )" && pwd )" rm $shDir/*.lastrun touch $shDir/`date +%Y-%m-%dT%H%M`.lastrun