-3

I have a file (for example system.log). I need to scan this file to find a specific string that must appear several times during a period of 5 minutes.

I imagine that I can make a script with 4 parameters:

  • the location of the file
  • the string to search
  • the number of times that the string appears
  • the period of time

If this script finds the string in the specified period of time it writes, for example, the message 'success'

Here's the begin of the script

#!/bin/ksh
#set -x

#############
# VARIABLES #
#############

location="/moteurs/websphere/7.0/esb/managed01/logs/"
file="SystemOut.log"
pattern="WSV0605W: Thread \"SIBFAPInboundThreadPool"
string=$(grep -ic "${pattern}" ${location}/${file})

Now that I've defined my variables, I don't know how can I make a function that scans SystemOut.log every 5 minutes.

4

2 回答 2

2

你知道我怎样才能创建这个外壳吗?

是的。使用您最喜欢的编辑器,编写 shell 脚本,执行它。你完成了。

于 2013-09-17T12:41:27.183 回答
0

只是一半的答案,但也许它会让你到达某个地方:

要每五分钟重复运行一次,您可以使用 sleep 循环:

while true
do
  echo "I'm doing something!"  # replace this by the actual code
  sleep $[5*60]
done

echo这将每五分钟运行一次代码(这里只是一个)。— 好的,加上代码需要的时间,所以不要依赖时间是否准确;为了准确,您可以使用

while sleep $[ 5*60 - $(date +%s) % (5*60) ]
do
  echo "I'm doing something!"  # replace this by the actual code
done

在执行代码之前,这将始终等待时钟上的完整 5 分钟点。

于 2013-09-18T08:16:44.680 回答