CRON Script not working right.

Bill Campbell freebsd at celestial.com
Wed Jan 17 04:41:16 UTC 2007


On Tue, Jan 16, 2007, Don O'Neil wrote:
>Anybody have any clues why a shell script run from root's CRON would act
>differently then when run directly from the command line?

Most often this is because the environment in the cron job is
different, either missing variables or having variables that
aren't set to a reasonable value (e.g. TERM).

The way I usually figure something like this out is to dump the
envioronment from the cron job, then do the same thing from the
command line, then compare the two.

#!/bin/sh
# this is the cron job
env | sort > /tmp/env.cron
exit;

Now from the command line ``env | sort > /tmp/cron.cli''.

Now run something like ``diff -u /tmp/env.cron /tmp/cron.cli'' to
see what is different.

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

When a place gets crowded enough to require ID's, social collapse is
not far away.  It is time to go elsewhere.  The best thing about space
travel is that it made it possible to go elsewhere.
                -- Robert Heinlein


More information about the freebsd-questions mailing list