Skip to main content
3 of 3
deleted 76 characters in body
Rafael Muynarsk
  • 2.7k
  • 4
  • 21
  • 26

That can be accomplished with the following script considering that grep -m1 doesn't work for you:

#!/bin/bash
  
java -jar xyz.jar &> "/tmp/yourscriptlog.txt" &
processnumber=$!
tail -F "/tmp/yourscriptlog.txt" | awk  '/Started server on port 8000/ { system("kill '$processnumber'") }'

Basically, this script redirects the stdout of your java code to a file with the command&> "/tmp/yourscriptlog.txt", the last & on the first line makes your code run as an isolated process and on the next line we have the number of this process with $!. Having the number of the process and a log file to tail we can finally kill the process when the desired line is printed.

Rafael Muynarsk
  • 2.7k
  • 4
  • 21
  • 26