在为图案求值时避免重复的pid

我编写了一个shell脚本来读取更新日志,并在有使用do while循环的OOM时发送电子邮件通知。

我能够收到有关OOM错误的电子邮件通知,但每次为发送的电子邮件生成重复的PID,这会产生巨大的数量。 当我正在为特定进程/管理服务器(weblogic)进行grepping时,重复的pids。 PFB我的脚本,有什么方法可以避免重复的PID,并且在执行grep时只能获得父PID。

#!/bin/sh # Script to read the updating log file and send mail for any errors : LogCheck.sh # SET VARIABLES logfile=BEA_HOME/SERVERS/Admin.log pattern="java.lang.OutOfMemoryError: Java heap space" #Read each line as it gets updating to the log file tail -fn0 $logfile | while read line ; do #check each line for our pattern echo "$line" | grep -i "$pattern" #Perform the below action if a line matches with our pattern if [ $? = 0 ]; then #Send an email echo "Found an error: $line" | mailx -s "please check the error" emailID fi done 

你可以使用uniqsort -u

 echo "$line" | grep -i "$pattern" | uniq 
 ps wp PID|grep PID 

你可以在没有grep的情况下做到 – 你会发现grep你删除了标题..