0

Let's say I have a script to start some java stuff

start.sh

myStuff=10.0.0.13
port=11212
servers=(10.0.0.9 10.0.0.10 10.0.0.11 10.0.0.12 10.0.0.14)
T=$1
R=$2

nohup java -jar myJar.jar -l ${myStuff} -p ${port} -t $T -r $R -m "${servers[@]/%/:11212}" &

If I start the script manually

./start.sh 64 1

for example, everything works as it should

now

echo "nohup ./start.sh 64 1" | at now

however, does nothing.

Why?

I've started similar scripts like this before (none that called java, though) and I can't seem to figure out how they differ.

EDIT

well, not quite nothing, the job DOES get scheduled and does disappear from the atq, but the jar is not started and there is no nohup.out anywhere.

EDIT 2

note that

echo "nohup ./start.sh 64 1 > help &" | at now

does create a help file (not a nohup.out file, though) but it's empty.

EDIT 3

note that changing the start.sh such that the path to the java binary is hardcoded:

nohup /usr/lib/jvm/java-1.7.0-openjdk-amd64/bin/java -jar myJar.jar -l ${myStuff} -p ${port} -t $T -r $R  -m "${servers[@]/%/:11212}" &

doesn't help either.

EDIT 4

echo "nohup java -version > help &" | at now

creates an empty help file (but no nohup.out).

Whereas

echo "nohup java -version > help 2>&1 &" | at now

will print

java version "1.7.0_111"
OpenJDK Runtime Environment (IcedTea 2.6.7) (7u111-2.6.7-0ubuntu0.14.04.3)
OpenJDK 64-Bit Server VM (build 24.111-b01, mixed mode)

into the help file (and not create a nohup.out file either).

EDIT 5

getting rid of the nohup, i.e.

java -jar myJar.jar ...

and then

echo "./start.sh 64 1" | at now

doesn't change anything.

hlovdal
  • 23,353
  • 10
  • 78
  • 148
User1291
  • 6,231
  • 5
  • 34
  • 75
  • 1
    I think your environment setting (like JAVA_HOME etc.) will be different depending whether you run the command at the command line or from `at`. look at the `nohup.out` file, or redirect the output of your command in a file. – Thomas Stets Nov 03 '16 at 12:11
  • @ThomasStets there is no ``nohup.out`` – User1291 Nov 03 '16 at 12:16
  • @ThomasStets nor does redirecting the output give any further information (see edits) – User1291 Nov 03 '16 at 12:27
  • I don't see a problem in `echo "nohup ./start.sh 64 1" | at now` part. Can you enable logs from Java? Perhaps log4j into a file? – alok Nov 03 '16 at 12:36
  • @alok My application would already create log files ... IF it were started. – User1291 Nov 03 '16 at 12:40
  • @ThomasStets hardcoding the java location doesn't change a thing (see edits). – User1291 Nov 03 '16 at 12:41
  • Could you please try running something like `java -version` and see what goes into the `help` file from your *Edit 2*? Also maybe redirect stderr into it by appending `2>&1`? – alok Nov 03 '16 at 12:50
  • @alok done. see edit above – User1291 Nov 03 '16 at 12:56
  • I'm not sure if this will help, but there is no need to run the job in the background if you are using `at`. Backgrounding and using `nohup` allows you to continue with your current shell and log out without interrupting the job when you run it manually. If the `at` daemon is running it for you, it is already being managed by a long-lived process. Try just running `java ...` in the foreground in the script. – chepner Nov 03 '16 at 12:58
  • You need to specify the absolute path to `start.sh`. – gsl Nov 03 '16 at 13:02
  • @chepner doesn't change anything (see edit) – User1291 Nov 03 '16 at 13:03
  • @gsl no, I do not. If it wouldn't find the script, it wouldn't be able to produce the ``help`` file, would it? (Also, I tried.) – User1291 Nov 03 '16 at 13:07

0 Answers0