Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running "crontab" with no options runs "crontab /dev/stdin" #28

Closed
tometzky opened this issue Feb 14, 2019 · 3 comments
Closed

Running "crontab" with no options runs "crontab /dev/stdin" #28

tometzky opened this issue Feb 14, 2019 · 3 comments

Comments

@tometzky
Copy link

su username -c crontab -l
What this command does?

It does not list crontabs for username - for this it should be su username -c "crontab -l". It runs "crontab" with no options.

But what bare "crontab" command does? It's not documented - man page says at least one option or a single non-option argument is required. So I'd expect it to just fail with an error. But it runs an equivalent of "crontab /dev/stdin" instead, deleting the current crontab if stdin is empty. The "crontab -" also works like this (also undocumented in the man page).

The help showing when invalid option is given states "Default operation is replace, per 1003.2". I don't know the exact wording of the standard, but it does not seem to force this non-intuitive and dangerous behaviour. IMHO it just means that when the file argument is provided then the default operation is to replace the crontab with its contents.

@t8m
Copy link
Member

t8m commented Feb 15, 2019

This stupid behavior is specified by POSIX, but let's see if anyone complains if we drop such error prone behavior.

Fixed by 39a67fd

@t8m t8m closed this as completed Feb 15, 2019
@mandree
Copy link

mandree commented Mar 17, 2021

This "stupid behaviour" (i. e. require crontab - instead of crontab to replace the user's scheduled commands) that was removed makes cronie incompatible with other applications that expect POSIX behavior, and I fail to see why incompatibilities need to be introduced just because users can't be bothered to read and understand the manual.

A middle ground would be to use isatty() when crontab is called without arguments that prints something like crontab of user JOHN will be replaced, press ^C to abort and run crontab -l to print or something.

@t8m
Copy link
Member

t8m commented Mar 17, 2021

I've implemented a different but IMO still sufficient middle ground of requiring the - argument only if isatty(STDIN_FILENO).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants