2

I am not Linux bash shell expert and I just wanted to check if my java process is still running.. I have written this simple bash shell script to verify if my java process is still executing...but the output is always 'Java is done...'

#!/bin/bash

until [ ` pgrep java ` ]; do
    echo Java still running...
    sleep 1
done
echo Java is done...

I would like to ask what is wrong in my until statement.

Mark Estrada
  • 9,013
  • 37
  • 119
  • 186

2 Answers2

0

In case of until, loop executes until the test command executes successfully. As long as this command fails, the loop continues.
In first iteration, while java is running, pgrep java is true and loop body is not executed.

haccks
  • 104,019
  • 25
  • 176
  • 264
0

If you want to use until, you should change the condition

until [ -z ` pgrep java ` ]; do
Waveter
  • 890
  • 10
  • 22
  • Sorry I got confused here but it works...Ohh so the -z test if the pgrep command returns an empty string? So if java is no longer running, it returns an empty string..that makes it true right? – Mark Estrada Mar 26 '18 at 08:30
  • @MarkEstrada Yes, you are right – Waveter Mar 26 '18 at 08:36