[SOLVED] script not running via crontab, run's fine manually
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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:
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.
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).
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.