Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synology Scheduler .sh java command not found

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.

Task Setup run by root

Adding the command to execute bash script. Adding log output.

enter image description here

Executing my new Task.

enter image description here

Checking the log to see the following error:

/volume1/homes/jar/sms.sh: line 1: java: command not found

Checking Java version/installation:

enter image description here

Checking execution of sh script manually (working):

enter image description here

Anyone with this same strange case? Any workarounds/ideas?

I tried

  • Rebooting my NAS
  • Uninstall / install Java8 package

but none worked.

like image 324
piguy Avatar asked Feb 02 '20 14:02

piguy


1 Answers

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.

like image 107
SubOptimal Avatar answered Nov 04 '22 19:11

SubOptimal