Solved Troubles with cron jobs

I must suck at cron jobs, because every system I have ever touched has never had working cron jobs. I basically want a cron job to take a recursive zfs snapshot of zroot every day at 2:00AM, but so far this hasn't happened. I edited the /etc/crontab file and added a line for creating and one for destroying old snapshots later at 2:05AM, here's what it looks like:

Code:
# Daily ZAP snapshots
0   2   *   *   *   root   zap snap 3w -r zroot   
5   2   *   *   *   root   zap destroy

Could someone tell me what's missing? This doesn't seem wrong to me
 
Put the full pathname to the file you want to execute. Cronjobs have a different environment from regular users or root, often having a restricted path.

You should also be able to see the cronjob's output in root's mail, which should help clue you in.
 
Alternatively, you could add /usr/local/bin to the PATH definition at the top of /etc/crontab.
 
And I suggest not editing /etc/crontab but instead use root's own crontab ( crontab -e). The reason is that /etc/crontab may get changed during an update/upgrade and that may remove your additions. Root's 'personal' crontab is never touched.
 
Thank you all for the help, that is exactly what I needed, thanks! I'll keep that in mind and make that change too SirDice. ZAP is working as it should now
 
You could use the zap user for that: doas/sudo -u zap crontab -e

EDIT: I do not remember if they (zap user and group) were created by default, but the last version in ports (updated today) seems to create them.

This is the mine one:

Code:
0,15,30,45 * * * * /bin/sh /usr/local/bin/zap snap 1d
7          0 * * * /bin/sh /usr/local/bin/zap snap 1w
14         0 * * 7 /bin/sh /usr/local/bin/zap snap 1m
 
According to crontab(5), you do not need to specify /bin/sh or the full path to zap when using the user crontab [1].
Several environment variables are set up automatically by the cron(8) daemon. SHELL is set to /bin/sh, PATH is set to /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin, and LOGNAME and HOME are set from the /etc/passwd line of the crontab's owner. HOME, PATH and SHELL may be overridden by settings in the crontab; LOGNAME may not.
Code:
#minute    hour	mday month wday	command
0,15,30,45 *    *    *     *    zap snap 1d
7          0    *    *     *    zap snap 1w
14         0    *    *     7    zap snap 1m
[1] Assuing zap is installed under the default /usr/local/ prefix and you have not overridden PATH or SHELL in the crontab.
 
Oh really? I'll have to look at that again for zap. I built it a few days ago and don't recall there being a user. I'll look into that :) one thing I think I remember though is I have to allow zap to have some zfs functionality on different datasets. However, I use iocage for jails so jails come and go and I'd like to just say that a user has x zfs functionality on an entire zpool

I don't have /bin/sh in my crontab file and it works for me with zap
 
Okay turns out you can delegate zfs permissions to zpools. Welp, that solves everything! I'll just have to prepare replication to an external system as soon as I let my friend finish playing around with my extra Intel NUC
 
Back
Top