dcron icon indicating copy to clipboard operation
dcron copied to clipboard

Exit non-zero when running `crontab -l -u user_that_doesnt_have_a_crontab`

Open h3xx opened this issue 4 years ago • 0 comments

I'd like to understand why this implementation of crontab is designed to exit zero when asking to list a crontab for a user that doesn't have a spool file. To me, it makes sense to exit non-zero in this instance. It would be great if crontab did this.

Not saying this project needs to follow suit, but cronie exits nonzero under the same conditions. Cronie is the default in CentOS and RHEL.

My particular use case is that I'm writing a shell script that backs up a user's current crontab to a file and deletes it:

if crontab -l -u www-data >/tmp/www-data.crontab.bak; then
    mv -i /tmp/www-data.crontab.bak .
    crontab -d -u www-data
fi

(I know could of course pipe the output to wc -l.)

h3xx avatar Feb 15 '21 17:02 h3xx