crontab: no changes made to crontab

Brian Inglis Brian.Inglis@SystematicSW.ab.ca
Sun Jul 7 21:09:37 GMT 2024


On 2024-07-06 04:50, Andrey Repin via Cygwin wrote:
> I'm trying to install a new cron job, and the thing fails claiming that it
> didn't see the edits I made to the file.

>>> # echo "USER=$USER" | crontab -
>>>
>>> # crontab -l
>>> # DO NOT EDIT THIS FILE - edit the master and reinstall.
>>> # (- installed on Sat Jul  6 13:35:43 2024)
>>> # (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
>>> USER=anrdaemon
>>>
>>> # crontab -e
>>> ### do some edits…
>>> crontab: no changes made to crontab

What is your editor, how is it configured, how is it invoked, and how are VISUAL 
and EDITOR defined?

Most commands that use an editor for some commands effectively invoke 
${VISUAL:-${EDITOR:-vi}}.

For example, I run gvim under X, it backgrounds, so I have VISUAL='gvim -f' and 
EDITOR=vim so gvim stays in the foreground for crontab, git, etc. and the same 
process and PID is used as forked.
For cygport, it only looks at EDITOR, so in ~/.cygwin_aliases, I have:

	alias cygport="EDITOR=\"$VISUAL\" cygport"

Your editor also has to behave as if it updates the temporary filename it is 
invoked with, as from:

	$ mktemp --tmpdir crontab.XXXXXXXXXX

for example /tmp/crontab.??????????, save changes into that file, and leave it 
changed when exiting, and other than nano's own /tmp/nano.?????? files, I see no 
special handling.

The source has the following note:

	https://github.com/vixie/cron/blob/master/crontab.c#L389

which assumes that editors rewrite original files rather than renaming/unlinking 
because that allows security issues, so it compares the fstat mtime to the saved 
value to detect changes.

> Piping a new file to the crontab works, but that's "slightly" cumbersome.
> What is it missing why it does not want to just work?
> -- Few moments later… ---
> It seems crontab dislikes safe file writes.

What do you mean by safe file writes?

>>> $ stat x > 1; nano x; stat x > 2; diff -u0 1 2

>>> $ stat x > 1; $EDITOR x; stat x > 2; diff -u0 1 2

What do these show?

If you are using `nano`, that should work, as it is used in almost every example 
from RaspberryPi, and someone would have complained!
Unless the Cygwin package config differs from the Debian config, and it does not 
appear to significantly.

> Is there a way around it that does not involve replacing crontab tool with my
> own script that has no such issue?

See above to fix the issue, or use:

	$ $VISUAL $HOME/$USER.crontab
	$ crontab $HOME/$USER.crontab
	$ crontab -l

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer     but when there is no more to cut
                                 -- Antoine de Saint-Exupéry


More information about the Cygwin mailing list