[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: root crontab @reboot for loop fails



On Sat, Jul 16, 2022 at 03:49:09AM +0100, Gareth Evans wrote:
> $ sudo crontab -l
> [...]
> @reboot for f in $(/usr/sbin/zfs list -t snap -o name|grep reboot); do /usr/sbin/zfs destroy $f;done
> @reboot /usr/sbin/zfs snap -r rpool@reboot
> 
> 
> Prepending "/usr/sbin/" to "zfs" doesn't make a difference.

Let me start by saying I don't know a single thing about ZFS.

My first reaction to this thread of yours is, "Well, read the email that
cron sends you and see what the errors are."

But that's the easy and obvious reaction.  My second reaction goes a
little bit deeper:

"All your crontab entries run in parallel.  So your first line which
has zfs in it, and your second line which also has zfs in it, those both
run at the same time.  Is that OK?"

Since I have no idea what any of those ZFS commands do, I can't tell
whether it's OK to have that race condition.  I suspect it's not OK,
but what do I know?

My third reaction goes something like this:

"If you wanted to run a bunch of commands a boot time, without setting
up systemd units for them, and proper dependencies, why didn't you just
use /etc/rc.local?"

Using a crontab to duplicate the functionality of rc.local seems odd to me.

Anyway, read your errors.  They may tell you what's wrong.  Figure out
whether your commands are allowed to run in parallel.  If they're not,
use a *script*, instead of a bunch of parallel commands.  That script
could be /etc/rc.local, or it could be a separate script that you call
from rc.local, or even call from crontab if you really insist.


Reply to: