1

My /etc/crontab contains the following lines:

0      *       *       *       *       root    /usr/bin/touch /root/IT_WORKED
1      *       *       *       *       root    /bin/sh -c '/sbin/zfs snap -r zpool@snapped_$(/bin/date '+%Y.%m.%d-%H.%M.%S-%Z-A') '
2      *       *       *       *       root    /bin/sh -c "/sbin/zfs snap -r zpool@snapped_`/bin/date '+%Y.%m.%d-%H.%M.%S-%Z_B'` "

When it's left to run, I see that the touched file is updated, so cron is clearly picking up the file on the hour. But the zfs snapshots aren't created. I've tested the 2nd and 3rd lines in shell and they both work fine as CLI commands, and snapshots are created.

So why aren't they running from cron?

Stilez
  • 1,221
  • 14
  • 28
  • shouldn't it be using full path for snap and date (e.g. `/usr/bin/date`) ? – zpangwin Jan 11 '21 at 06:24
  • Snap is an arg to /sbin zfs so no. Date changed to /bin/date thanks but didn't help – Stilez Jan 11 '21 at 07:05
  • 3
    `%` is special in crontabs. See duplicate question+answer. – Kusalananda Jan 11 '21 at 07:43
  • @Kusalananda - thanks! Didn't know to look for this. – Stilez Jan 11 '21 at 09:20
  • Cron runs with an almost empty environment. Make a habit of using minimal shell scripts which you can easily test in an empty environment. See [this](https://serverfault.com/questions/337631/crontab-execution-doesnt-have-the-same-environment-variables-as-executing-user) – Claus Andersen Jan 11 '21 at 11:49

0 Answers0