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 > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 02-11-2010, 12:40 PM
Walt Rarus
 
Default Cron, bash, and java interacting badly?

I have a java (clojure, actually) program which is invoked via a bash script. When the script is invoked from the shell, the java program always runs and succeeds. However, when the script is invoked via a cron job, the java program always runs and crashes with a null pointer exception.


Any thoughts on how to debug the situation?
 
Old 02-11-2010, 01:08 PM
Alex Schuster
 
Default Cron, bash, and java interacting badly?

Walt Rarus writes:

> I have a java (clojure, actually) program which is invoked via a bash
> script. When the script is invoked from the shell, the java program
> always runs and succeeds. However, when the script is invoked via a
> cron job, the java program always runs and crashes with a null pointer
> exception.

Cron jobs have a limited environment. The $PATH is shorter, many
environment variables are not set. Maybe this is the cause?

> Any thoughts on how to debug the situation?

I would add "env > /tmp/myscript.env" to the top of the script, this puts
all environment variables and their values into /tmp/myscript.env. Compare
the outputs with diff, maybe you spot something which explains the
behaviour.

Maybe you can replace the call to the script in your crontab with
something like "bash -il /path/to/myscript", forcing it to run in an
interactive login shell. I have not tried this, though, it's just an idea.

Wonko
 
Old 02-11-2010, 01:35 PM
Alan McKinnon
 
Default Cron, bash, and java interacting badly?

On Thursday 11 February 2010 15:40:09 Walt Rarus wrote:
> I have a java (clojure, actually) program which is invoked via a bash
> script. When the script is invoked from the shell, the java program always
> runs and succeeds. However, when the script is invoked via a cron job, the
> java program always runs and crashes with a null pointer exception.
>
> Any thoughts on how to debug the situation?

Same resolution as every other time cron errors come up:

cron does NOT run in a shell with an environment. It does not use
/etc/profile.

You must set up your own environment in your script run from cron. For
example, you are likely missing JAVA_HOME and friends.


--
alan dot mckinnon at gmail dot com
 
Old 02-11-2010, 04:20 PM
Neil Bothwick
 
Default Cron, bash, and java interacting badly?

On Thu, 11 Feb 2010 16:35:03 +0200, Alan McKinnon wrote:

> You must set up your own environment in your script run from cron. For
> example, you are likely missing JAVA_HOME and friends.

"source /etc/profile" at the top of the script often works.


--
Neil Bothwick

If at first you don't succeed, skydiving is not for you.
 
Old 02-12-2010, 08:57 PM
Walt Rarus
 
Default Cron, bash, and java interacting badly?

On Thu, Feb 11, 2010 at 12:20 PM, Neil Bothwick <neil@digimed.co.uk> wrote:



"source /etc/profile" at the top of the script often works.


@Neil:

Well, that does the trick!

But I don't understand why. In my initial post I withheld information in order to be sure the focus wouldn't be on the Clojure program itself. I withheld the fact that my failing program was only a slight variation on 4 other programs which all always worked both via cron and the commandline.

IOW, the restricted cron environment doesn't impact the other 4 programs. Well, I'll happily put the source statement in and at some point try to figure out what it adds to avoid the crash.

BTW, I love the quotations following your sig. Speaking of "source", are you willing to reveal the source of these beauties?



@Alex, Alan:

Thanks for your contributions. I learned a few things as a result.
 
Old 02-12-2010, 09:53 PM
Neil Bothwick
 
Default Cron, bash, and java interacting badly?

On Fri, 12 Feb 2010 16:57:09 -0500, Walt Rarus wrote:

> BTW, I love the quotations following your sig. Speaking of "source",
> are you willing to reveal the source of these beauties?

Yes, it's a place called "the Internet" ;-)


--
Neil Bothwick

CPU: (n.) acronym for Central Purging Unit. A device which discards or
distorts data sent to it, sometimes returning more data and sometimes
merely over-heating.
 

Thread Tools




All times are GMT. The time now is 07:07 AM.

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