FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 12-07-2010, 01:34 PM
"James B. Byrne"
 
Default difference between cron and shell invocation.

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?



--
*** E-Mail is NOT a SECURE channel ***
James B. Byrne mailto:ByrneJB@Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-07-2010, 01:39 PM
 
Default difference between cron and shell invocation.

James B. Byrne 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?

Sure - it's pretty obvious that something in the environment is missing.
Try putting env in the cron job, or run the actual job as a shell script,
and in the script, put env and pipe that to a file, so that you can then
compare that with your env o/p as root.

mark

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-07-2010, 01:40 PM
Tony Molloy
 
Default difference between cron and shell invocation.

On Tuesday 07 December 2010 14:34:33 James B. Byrne 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?



Check the paths in cron. They are not necessarly the same as the paths for the shell.



Tony
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-07-2010, 01:57 PM
Robert Heller
 
Default difference between cron and shell invocation.

At Tue, 7 Dec 2010 09:34:33 -0500 (EST) CentOS mailing list <centos@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
shell?:

</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@deepsoft.com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/ www.asciiribbon.org -- against proprietary attachments



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-07-2010, 02:02 PM
"James B. Byrne"
 
Default difference between cron and shell invocation.

On Tue, December 7, 2010 09:49, Brent L. Bates wrote:
> If you aren't already doing so, use the full path to the
> commands you are

I have done as you suggest and that indeed has solved the problem.
Thank you very much.

Regards,

--
*** E-Mail is NOT a SECURE channel ***
James B. Byrne mailto:ByrneJB@Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-07-2010, 02:21 PM
"James B. Byrne"
 
Default difference between cron and shell invocation.

Question. In a chained cron job like this:

sshfs . . . && /usr/bin/rsync . . . | /bin/mail -s . . . && .
. .

Is there anyway to get a failure message from the first part to be
emailed or logged?

Given the resolution of this problem I gather that sshfs must not
have been found and therefore I would expect an error to be reported
somewhere. The chained commands evidently interfered with the
propagation of this error which would have immediately identified
the source of the problem. Is it possible to get errors from the
individual parts of such chained commands forwarded to an email
address, or logged in the system log, or both?

--
*** E-Mail is NOT a SECURE channel ***
James B. Byrne mailto:ByrneJB@Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-07-2010, 02:39 PM
Robert Heller
 
Default difference between cron and shell invocation.

At Tue, 7 Dec 2010 10:21:27 -0500 (EST) CentOS mailing list <centos@centos.org> wrote:

>
> Question. In a chained cron job like this:
>
> sshfs . . . && /usr/bin/rsync . . . | /bin/mail -s . . . && .
> . .
>
> Is there anyway to get a failure message from the first part to be
> emailed or logged?
>
> Given the resolution of this problem I gather that sshfs must not
> have been found and therefore I would expect an error to be reported
> somewhere. The chained commands evidently interfered with the
> propagation of this error which would have immediately identified
> the source of the problem. Is it possible to get errors from the
> individual parts of such chained commands forwarded to an email
> address, or logged in the system log, or both?

It is probably easiest to create a shell script with all of the chaining
there and use shell script flow control to deal with mailing/logging
errors:

#!/bin/sh -e
sshfs . . .
/usr/bin/rsync . . . 2>&1 | /bin/mail -s . . .
..

Or something like that (eg using '|| error-handling/reporting code'
instead of -e).

>

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



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-07-2010, 02:40 PM
 
Default difference between cron and shell invocation.

James B. Byrne wrote:
> Question. In a chained cron job like this:
>
> sshfs . . . && /usr/bin/rsync . . . | /bin/mail -s . . . && .
> . .
>
> Is there anyway to get a failure message from the first part to be
> emailed or logged?
>
> Given the resolution of this problem I gather that sshfs must not
> have been found and therefore I would expect an error to be reported
> somewhere. The chained commands evidently interfered with the
> propagation of this error which would have immediately identified
> the source of the problem. Is it possible to get errors from the
> individual parts of such chained commands forwarded to an email
> address, or logged in the system log, or both?
>
If you're going to get that complicated, why not just write a short shell
script, and run that via cron. Then you can set your environment
explicitly (as opposed to in your crontab, which some folks like to do).
Also, if you want logs from each piece, you could then break it up, and
dump/read stuff from temp files.

mark

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-07-2010, 02:54 PM
Les Mikesell
 
Default difference between cron and shell invocation.

On 12/7/10 9:21 AM, James B. Byrne wrote:
> Question. In a chained cron job like this:
>
> sshfs . . .&& /usr/bin/rsync . . . | /bin/mail -s . . .&& .
> . .
>
> Is there anyway to get a failure message from the first part to be
> emailed or logged?
>
> Given the resolution of this problem I gather that sshfs must not
> have been found and therefore I would expect an error to be reported
> somewhere. The chained commands evidently interfered with the
> propagation of this error which would have immediately identified
> the source of the problem. Is it possible to get errors from the
> individual parts of such chained commands forwarded to an email
> address, or logged in the system log, or both?


Cron should default to mailing anything sent to stdout or stderr to the owner of
the job if you don't redirect it elsewhere.

--
Les Mikesell
lesmikesell@gmail.com
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 09:57 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org