Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shell script not running via crontab, runs fine manually

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 its 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:

#!/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?

like image 772
astro Avatar asked Feb 08 '10 21:02

astro


People also ask

Why is my crontab script not running?

One of the most frequent causes for the crontab job not being correctly executed is that a cronjob does not run under the user's shell environment. Another reason can be – not specifying the absolute path of the commands used in the script.

How do I make sure my crontab is running?

Method # 1: By Checking the Status of Cron Service Running the “systemctl” command along with the status flag will check the status of the Cron service as shown in the image below. If the status is “Active (Running)” then it will be confirmed that crontab is working perfectly well, otherwise not.


1 Answers

Try specifying the full path to the jar file:

/usr/bin/java -jar /path/to/Pharmagistics_auto.jar -o
like image 86
Dennis Williamson Avatar answered Nov 27 '22 02:11

Dennis Williamson