我发现了一些奇怪的错误。我想增加一个计数器,但这个变量不是在可见的范围之外。错误与壳脚本
如下脚本:
## $1 - The file which should be examined
## $2 - The time passed between the checks. If $2 is 5 then all lines from the last 5 minutes are taken
## $3 - The Errormessage to search for
outputOK="OK - nothing happened"
output_logcheck=0;
errlines="";
cat $1 | grep "$3" | while read line
do
linedate=`date -d "$(echo $line | cut -d " " -f 2)" '+%s'`
nowdate=`date '+%s'`
if [ $(($nowdate - (60 * $2))) -le $linedate ]
then
$output_logcheck=$[$output_logcheck+1]
$errlines="${errlines} -- ${line}"
fi
done;
if [ $output_logcheck -eq 0 ]
then
echo $outputOK
else
echo "CRITICAL - There are -= ${output_logcheck} =- $3 -- Lines: $errlines"
fi
所以我不知道什么尝试。 在此先感谢。
有关于这个问题的常见问题解答条目,仅供将来参考:[“我在流水线中的循环中设置变量,为什么在循环终止后它们消失?或者,为什么我不能读取数据以读取?“](http://mywiki.wooledge.org/BashFAQ/024) –