Public bug reported:

I wrote a script to automatically edit a crontab across a fleet of machines.
The script works something like this:

   ex $crontab << EOT
    <ex commands to effect the changes I want>
   wq!
   EOT

I set EDITOR to point at that script, and then run "crontab -e", only to
find that the program says "No modification made". I carefully debugged
my script to ensure that it was actually making a change. In spite of
the change, crontab(1) claims "No modification made" and rejects the
changes.

After other attempts at troubleshooting failed, I delved into the source
code. The "No modification made" error is reported after "crontab"
checks the file modification time, which it does both before and after
calling $EDITOR.

The check is done like this:

            if (statbuf.st_mtime == fsbuf->st_mtime) {
                    return 1; /* No change to file */
            }

According to the stat(2) Linux man page, "st_mtime" is actually a macro
defined as:

    #define st_mtime st_mtim.tv_sec

So it seems that the problem is that editing a file by script takes less
than a second, and this method of checking a file's modification time
only provides 1-second resolution.

It seems that attempting to move away from using the st_mtime field
would introduce some portability problems, since Linux and MacOS X
provide incompatible ways to get subsecond precision on a file's
modification time.

In the meantime, I will call sleep(1) from my script to ensure that
enough time passes that crontab can see that there was a change.

** Affects: cron (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1854891

Title:
  Editing crontab by script doesn't work

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/cron/+bug/1854891/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to