Facing a problem while running Java code from CRON job.
I am trying to run a ".sh" file from CRON like this:
* * * * * root sh /run-test.sh >> /var/log/cron.log
# empty line
and this run-test.sh has:
java HelloWorld
When, I navigate to root folder i.e. "/" and run command:
sh run-test.sh
It will run my HelloWorld class properly and gives me desired output.
But, through CRON tab it always say's:
Error: Could not find or load main class HelloWorld
I am not able to Judge what can be the reason for this. Immediate replies will be helpful. Thanks
you might need to change the current working directory for cron.
* * * * * root cd / && sh /run-test.sh >> /var/log/cron.log
you dont have any absolute paths in your script , so it will be running relative to the working directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With