Bad Minute Error in Crontab File

Tim Frost timfrost at xtra.co.nz
Wed Nov 16 20:43:16 UTC 2005


On Wed, 2005-11-16 at 15:12 +0000, Hakim Singhji wrote: 
>  <sean <at> seanmiller.net> writes:
> > I would not recommend calling a crontab file something like ~/bin/sig -
> > it's very unintuitive, assuming that is what you meant to do and this is
> > not a mistake.
> 
> I'm afraid that I may misunderstand how crontab works. See I was trying to run 
> the file ~/bin/sig using crontab. I thought that crontab schedule the time 
> sequence for jobs to repeat and the last argument on the line was the filename 
> to be executed. Is this not correct? If someone could show me there an example 
> of "crontab -e". This may be helpful.
crontab consists of several parts:
* the cron daemon, which runs jobs specified in crontab files
* the "crontab" files:
    /etc/crontab   - standard system tasks that are run
    /var/spool/cron/crontabs/* - user cron jobs

* the crontab command, which manages the user cron jobs



the command "crontab -e" asks crontab to invoke an editor, to edit a
copy of your crontab file.  If you don't have a crontab file, this
command will create one for you.  

The crontab file has lines in it which tell cron what program to run,
and when to run it.
For example, to run your program at 2 AM every day, you would have an
entry that looks like the following:
  0 2 * * * /home/hzs202/bin/sig

What the command you issued was doing was saying "take the file
~/bin/sig, and use it as a crontab file", when you wanted to say
"schedule the program ~/bin/sig at a particular time".  The error that
occurred is because ~/bin/sig does not have the time fields that are
required for the contents of a crontab file.


> > Personally I would also archive them so that if you muck up the crontab
> > you can look back at what it was before.
> 
> Good idea... what program could do this tar? Or should I write a shell script 
> that adds random #'s.

tar could be used for this, but so could a simple script that copies the
crontab to a subdirectory, with the current timestamp, then runs the
crontab command to install the new file.  Or a script like the
following, which uses the crontab command itself:
#!/bin/bash
# edit the crontab using crontab -e
crontab -e

# get the current time stamp (in format YYYYMMDDhhmmss, so that the 
#   directory listing is cronological)
TS=`date +%Y%m%d%H%M%S`

#change ARCHDIR to be a directory where  you want 
# the crontab archives to be held
ARCHDIR=~/archives
# create the archives directory if it doesn't exist
if [ ! -d $ARCHDIR ]
then
  mkdir $ARCHDIR
fi

# save a copy of the new crontab to $ARCHDIR/crontab.$TS
crontab -l > $ARCHDIR/crontab.$TS

echo "new crontab installed and saved as $ARCHDIR/crontab.$TS"

#END

If you save that script, and run it to edit the crontab file, you will
get a history of different versions.  Note that the script will create a
new archive copy even if the crontab is NOT altered at all.  The diff
command could be used to track the actual differences between versions,
and a version control system, such as CVS, could be used as well.

> 
> Hakim

Tim






More information about the ubuntu-users mailing list