You want to use the tail
command. tail -n 1
will give you the last line of the file or redirected standard output, while tail -f
will keep the tail
program going until you cancel it yourself.
For example:
echo -e "Jello\nPudding\nSkittles" | tail -n 1 | if grep -q Skittles ; then echo yes; fi
The first section simply prints three lines of text:
Jello
Pudding
Skittles
The tail -n 1
finds the last line of text ("Skittles
") and passes that to the next section.
grep -q
simply returns TRUE if your pattern was found or FALSE if not, without actually dumping or outputting anything to screen.
So the if grep -q Skittles
section will check the result of that grep -q Skittles
pattern and, if it found Skittles
, prints 'yes
' to the screen. If not, nothing gets printed (try replacing Skittles
with Pudding
, and even though it was in the original input, it never made it out the other end of the tail -n 1
call).
Maybe you can use that logic and output your .jar to standard output, then search that output every 5 minutes?