Step 1, as already said above: Put all the work you need to do into a small script (which you can install in /usr/local/sbin for example).
Step 2: Make sure that shell script works when called by hand *with a minimal path*. Remember, cron sets the path to a small set. If your script is called /usr/local/sbin/foobar, then I would test is as follows:
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin /usr/local/sbin/foobar
. Ideally, you could even inside your script become completely independent from the path, by calling all executables by explicit path (that has both advantages and disadvantages).
Step 3: Temporarily create another really tiny shell script, which you just use to verify that calling things from cron works. For example, here is test script /usr/local/sbin/blatz:
Code:
#!/bin/sh
date >> /tmp/blatz.log
Put that tiny script in crontab, and make sure (by watching the log file) that it gets run. Make sure this shell script has execute permissions.
Step 4: Create yet another three tiny shell scripts, to test that getting the output of cron jobs into e-mail works. The first one should test stdout; it could just contain
echo Hallo `date`
with the appropriate
#!/bin/sh
hash-bang line. The second one should test stderr, with
echo Hallo `date` > /dev/stderr
. The third one is like the second one, but it shall fail, by returning a non-zero code: simply add
exit 1
to the end of it. Let all three run from crontab, and make sure you get all the appropriate e-mails, and that you know how to distinguish success from failure and get the debugging data.
As you see, what I did above is break down the problem to various components, each of which could have problems. Once all this works to your satisfaction, adding the "real" script to crontab just *has to work*.