Search code examples
ubuntucroncron-task

Crontab - "bad day-of-week" error, when trying to schedule a task to run each other day-of-week using "dow/2"


I try to schedule a task in Ubuntu 16.04 using crontab:

45 2 * * 4/2 sh /var/lib/libvirt/images/backups/backup_res.sh

I want it to be executed every other Thursday at 2:45AM. However, I keep getting bad day-of-week error. If I remove /2, it works fine. What could be the problem?


Solution

  • I think the best way is:

    45 2 * * Thu expr `date +\%s` / 604800 \% 2 >/dev/null || sh /var/lib/libvirt/images/backups/backup_res.sh
    

    please see this Q&A