LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-08-2010, 11:33 AM   #1
astroboiii
Member
 
Registered: Feb 2004
Posts: 83

Rep: Reputation: 15
script not running via crontab, run's fine manually


Hey guys,

Before you guys jump on me for asking this question which is asked a million times over and over.

Yes I have tried exporting my paths and variables and crontab still will not run my script. I'm sure I am doing something wrong.

I have a shell script which runs a jar file. This is not working correctly.

After reading around I have read this is commonly due to incorrect paths due to cron running via it's own shell instance and therefore does not have the same preferences setup as my profile does.

here is what my script looks like today after several modifications:

Code:
#!/bin/bash --

. /root/.bash_profile

usr/bin/java -jar Pharmagistics_auto.jar -o

...
those are the most important pieces of the script, the rest are straightforward shell based.

Can someone tell me what I am doing wrong?

If you need more info please let me know and I will make sure to include them. Thank's
 
Old 02-08-2010, 11:38 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
try to change
Code:
usr/bin/java -jar Pharmagistics_auto.jar -o
to
Code:
/usr/bin/java -jar Pharmagistics_auto.jar -o
Does it run from the commandline?
 
Old 02-08-2010, 12:22 PM   #3
astroboiii
Member
 
Registered: Feb 2004
Posts: 83

Original Poster
Rep: Reputation: 15
Thank you for the quick response Repo.

My apologies I must have copied and pasted incorrectly the '/' is present in my script file. and it does indeed work when run manually from the commandline. Am i loading my user profile correctly at the start of the script?

Did you want to see the my crontab and profile environment var's, maybe that would provide more insight.
 
Old 02-08-2010, 12:26 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
You could try changing #!/bin/bash -- to #!/bin/bash -l (that's a letter l) which will simulate a login. If your script then works from cron you know it is a shell customisation issue.

You could try sourcing /etc/profile as well as /root/.bash_profile (assuming /etc/profile is not sourced in /root/.bash_profile).
 
Old 02-08-2010, 12:36 PM   #5
astroboiii
Member
 
Registered: Feb 2004
Posts: 83

Original Poster
Rep: Reputation: 15
Hi Catkin,

I tried changing the #!/bin/bash to #!/bin/bash -l to no avail.

I wasn't sure what you meant by sourcing /etc/profile as well as /root/.bash_profile can you be more specific?

Thank's again for the help
 
Old 02-08-2010, 02:07 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by astroboiii View Post
I tried changing the #!/bin/bash to #!/bin/bash -l to no avail.

I wasn't sure what you meant by sourcing /etc/profile as well as /root/.bash_profile can you be more specific?
Then it's not a shell customisation thing. "sourcing" is executing a file of shell commands in the curent shell -- which you are doing via the . command.

Is the program reading from or writing to the terminal?
 
Old 02-08-2010, 02:26 PM   #7
astroboiii
Member
 
Registered: Feb 2004
Posts: 83

Original Poster
Rep: Reputation: 15
ahh okay that makes sense. thank's for breaking that down.


The program is indeed writing to the terminal in a few spots. I have tried to capture it's output in log files but they remain empty. However, my shell commands within the script file do seem to be working just fine, it's only the java call which does nothing.
 
Old 02-08-2010, 04:56 PM   #8
astroboiii
Member
 
Registered: Feb 2004
Posts: 83

Original Poster
Rep: Reputation: 15
anyone have any thoughts?
 
Old 02-08-2010, 05:20 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
cron is a detached process, it doesn't have any terminals to write to, so you'd have to re-direct to files if possible. If you're specifying to write direct to a terminal inside java (I'm not a java programmer), then you'll have to change that.
Might be best if you can provide a short working version of the src for what's going wrong.
 
Old 02-08-2010, 06:57 PM   #10
astroboiii
Member
 
Registered: Feb 2004
Posts: 83

Original Poster
Rep: Reputation: 15
i was redirecting the output into files to be able to see the output.

I fixed the issue, i needed to also have the absolute path of the .jar file itself in the shell script. That did the trick.

Thank's for your guidance everyone!
 
Old 02-08-2010, 10:36 PM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by astroboiii View Post
I fixed the issue, i needed to also have the absolute path of the .jar file itself in the shell script. That did the trick.
Glad you solved it. Did you figure out why it worked at the command prompt but not when run from cron?
 
  


Reply

Tags
crontab, shell



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script not Running from Crontab venkatramanj SUSE / openSUSE 3 01-13-2010 05:15 AM
Script not running properly in cron though runs well if run manually. linuxlover.chaitanya Linux - Newbie 4 01-15-2009 03:31 AM
Running a script with crontab. glore2002 Slackware 3 06-05-2008 08:48 PM
Bash script not running within crontab job WrightExposure Linux - General 3 01-23-2007 06:28 PM
error running script on crontab haora Linux - Newbie 3 03-11-2005 04:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration