[CentOS] difference between cron and shell invocation.

Tue Dec 7 14:57:10 UTC 2010
Robert Heller <heller at deepsoft.com>

At Tue, 7 Dec 2010 09:34:33 -0500 (EST) CentOS mailing list <centos at centos.org> wrote:

> I have a fairly involved root cron task that I moved verbatim from
> another server. On the original server, this task ran without
> problem.  On the new server, when this task runs via cron, which I
> confirm is happening by looking in the cron log, no files are
> transferred and no error is reported.  However, if I copy cron
> command from roots crontab and paste it into a terminal session on
> the new server then the task runs to completion and the files are
> transferred.
> This task involves sshfs, fuse, and rsync and employs pki
> certificates for authentication.  The fact that it works from the
> shell without alteration and yet not from cron is the issue.
> Does anyone have any idea where I would start to track down what is
> going on?

Things to check:

Environment issues: PATH, SHELL, etc.

I would put in calls to logger and/or echo to log what is going on. 
Adding a '-v' (verbose flag) to selected commands to generate additional
debug information can also help.

Is anything making use of stdin?

Does the script still work if you do something like from an interactive

</dev/null ./script

Is anything dependent on having access to an actual console device (eg
/dev/tty)?  That is, are any of the programs trying to be interactive?

What are you doing about stderr's channel?  Does adding '2>&1' to the
command in crontab prove enlightening?


Robert Heller             -- 978-544-6933 / heller at deepsoft.com
Deepwoods Software        -- http://www.deepsoft.com/
()  ascii ribbon campaign -- against html e-mail
/\  www.asciiribbon.org   -- against proprietary attachments