简体   繁体   中英

A shell script to read a text file and then run a java program

I have a java program that stops often due to errors which is logged in a .log file. What can be a simple shell script to detect a particular text line say

stream closed

and then run the following command

java -jar xyz.jar

Here's a bash script to do something like that (may contain typos):

#!/bin/bash
tail -f logfile.txt | grep "stream closed" |
while read line
do
   java -jar xyz.jar
done
if grep 'stream closed' filename.log >/dev/null
then java -jar xyz.jar
fi
T1="`cat youfile.log  | grep 'stream closed'`"
if [ "$T1" = "stream closed" ]; then
   java -jar xyz.jar
fi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM