Editing

If you set your VISUAL environment variable to vim, and then use 'crontab -e' to edit your crontab, you will probably find that the crontab is unchanged.

A Google search showed that other people had had this problem, and many had resorted to using other editors (or even crons) to get around it. Some had discovered that putting vim into vi-compatible mode fixed the problem - but what's the point of using vim if it behaves like vi?

I eventally found a forum that hinted at the real solution - it had been discovered that using the vim setting 'backupcopy=yes' worked. I didn't know what the backupcopy setting did, and so looked it up in the vim manual, and there was an explanation of the 'crontab -e' problem!!!

It seems that you have to use 'backupcopy=yes' to get crontab to recognize that you have changed the file, but that it's good idea to use the default setting of 'backupcopy=auto' for most other editing. To achieve this, I've used the following two lines in my (and root's) .vimrc file:

filetype on
autocmd FileType crontab set backupcopy=yes

Seeing error output

With a standard Slackware installation, you will not see any error output from scripts that you put in directories such as /etc/cron.daily. This is because root's crontab redirects stdout to /dev/null, and the /usr/bin/run-parts script, which is run from the crontab, redirects stderr to the same place as stdout (i.e. /dev/null).

If you remove the redirections from the crontab, then any output from the scripts will get mailed to root. To view this mail, do:

su -
mail


There are two problems with this.

Firstly, you probably won't notice that root has mail, and so may be unaware that there has been an error. I've dealt with this by redirecting root's mail to myself on sage (see NettleSetup).

Secondly, the run-parts script contains echo commands, so there will always be output that will be mailed to root! I've edited /usr/bin/run-parts to get around this, replacing the lines:

echo "$SCRIPT:"
echo
$SCRIPT 2>&1
echo

by:

TEMPFILE=$(mktemp)
$SCRIPT >$TEMPFILE 2>&1
if [ -s $TEMPFILE ]
then
echo "$SCRIPT:"
echo
cat $TEMPFILE
echo
fi
rm -f $TEMPFILE