I wrote a program in Java, which uses the RXTX serial port, so I had to include an additional library. At first I ran it from SSH, and it was working properly. After that, I was running some test directly on the given computer, and it also worked normally. At this point, I'm trying to make it work on the specific computer, however, with no display, and it should run automatically (I did it with crontab earlier, and I planned to use it again). So I reused an old script below.
#!/bin/bash if [ ps x $UID | grep -v grep | grep -c `java` ]; then # process fut, nem kell semmi exit 0; else # export DISPLAY=:0; exec sudo java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar '/foo/bar.jar'; fi pidof java if [[ $? -ne 0 ]] ; then #export DISPLAY=:0 exec sudo java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar '/foo/bar.jar' & fi
Which worked correctly for an another program before (that one had GUI, this one does not). I can still run it from SSH with the command behind the exec, but when I try to use shell script, it gives
-bash: [: missing `]'
And also the standard error message that I use java in the wrong way, even tough directly it still works
sudo java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar '/foo/bar.jar'
The script supposed to check if java is running, and restarting my program if it doesn't, in crontab and init.d. However, at this point it does nothing at all. (And it should be able to read from console, right? I cannot check it, since it doesn't run without a display.)
The other programs worked correctly, however they just run java -jar "file", without any additional parameters.
Sep 18 14:03:38 raspberrypi systemd: [/etc/systemd/system/rxtxcomm.service:4] Executable path is not absolute, ignoring: java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar "/home/pi/forgokapu/dist/forgokapu.jar"
Something is fishy. Trying to run with absolute java...
Ok, now it seems to work, except java is throwing error messages, because it's not able to read a new line when it is not supposed to do so. It requires an investigation, but in the Java code. Thanks for your help!