On Thu, 11 Sep 2003 04:38:43 -0700, Sylvie Stone wrote:
surely:
$ crontab -e
does the same thing?
Andy
Hi Andy - sorry but crontab -e does *not* do the same thing. crontab
-e edits the cron file directly creating the same senario whereby if
the computer crashes you lose your file.
Sorry to be so argumentative, but you are blatently wrong!!!!
Looking the source code for crontab (vixie_cron, 3.0.1, crontab.c) reveals
that a -e switch does the following:
1)Opens the existing crontab readonly (this won't cause the loss of a
file if the computer crashes) (line 305)
2)Opens a new file called /tmp/crontab.{PID} (where PID is the Process
Identifier for the crontab process) with write access (this won't cause
the loss of the previous file if the computer crashes) (line 318/319)
3)Copies the content of the readonly original opened in step 1 to the new
temp file opened in step 2 (lines 357-359)
4)It then forks and opens the editor to edit the temp file (line 393)
5)The parent process waits for the editor to finish (line 423)
6)If all was OK with the edit, then call the replace_cmd function (line
451 calling line 491)
7)Only at this point does the real crontab file get opened for write
access and is liable to be lost if the power is lost.
However this is also the point that occurs if you just put the file on the
command line (it sets a default option of opt_replace (line 199) and sets
the filename of the incoming file to the file you specify (line 200) and
runs the replace_cmd in exactly the same manner (line 124)
So, sorry to be nasty in the first line, but that's the great thing about
Linux - it's not "I think it works this way" - it's "I know it works this
way because I've looked at the source code and it blatently does!".
Cheers,
Andy