I have a bash script thats only task is to execute a jar file.
sms.sh
java -jar /volume1/homes/jar/smssender.jar
Using my Synology NAS I set up a task.
Adding the command to execute bash script. Adding log output.
Executing my new Task.
Checking the log to see the following error:
/volume1/homes/jar/sms.sh: line 1: java: command not found
Checking Java version/installation:
Checking execution of sh script manually (working):
Anyone with this same strange case? Any workarounds/ideas?
I tried
but none worked.
When the Synology task scheduler executes the script sms.sh
the PATH setting is taken from script /etc/crontab
. Which does not contain the Java path.
The default login shell environment is defined int /etc/profile
. At the end there is a section to add the Java path.
PATH=$PATH:/var/packages/Java8/target/j2sdk-image/bin # Synology Java runtime enviroment
PATH=$PATH:/var/packages/Java8/target/j2sdk-image/jre/bin # Synology Java runtime enviroment
JAVA_HOME=/var/packages/Java8/target/j2sdk-image/jre # Synology Java runtime enviroment
CLASSPATH=.:/var/packages/Java8/target/j2sdk-image/jre/lib # Synology Java runtime enviroment
LANG=en_US.utf8 # Synology Java runtime enviroment
export CLASSPATH PATH JAVA_HOME LANG # Synology Java runtime enviroment
As already stated in already given comments sourcing a profile script which is meant for an interactive shell isn't suggested. You might mimic the behavior of the /etc/profile
script in your sms.sh
script to set CLASSPATH PATH JAVA_HOME LANG.
The raised points about hardcoding the path in your script and the resulting reduced portability might have a lover precedence in this specific case.
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