我有一个优化我的bash脚本的问题。我有几个模式需要在日志文件中查找。如果其中一个模式在日志文件中列出,则执行SOMETHING。到目前为止,我有这个,但我怎么能优化它没有这么多的变数:如何使用bash脚本在日志文件中搜索多个字符串
search_trace() {
TYPE=$1
for i in `find ${LOGTRC}/* -prune -type f -name "${USER}${TYPE}*" `
do
res1=0
res1=`grep -c "String1" $i`
res2=0
res2=`grep -c "String2" $i`
res3=0
res3=`grep -c "String3" $i`
res4=0
res4=`grep -c "String4" $i`
if [ $res1 -gt 0 ] || [ $res2 -gt 0 ] || [ $res3 -gt 0 ] || [ $res4 -gt 0 ]; then
write_log W "Something is done ,because of connection reset in ${i}"
sleep 5
fi
done