简体   繁体   English

读取文本文件然后运行Java程序的Shell脚本

[英]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. 我有一个java程序经常因.log文件中记录的错误而停止。 What can be a simple shell script to detect a particular text line say 什么是检测特定文本行的简单shell脚本,例如

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): 这是一个bash脚本,可以做类似的事情(可能包含错别字):

#!/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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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