What my script does is:
- Append data to a file on a continuous basis.
- If an error pattern is observed, then do something.
I need feedback on the way I am grepping for patterns in the continuously appended file. For grep, I am creating a pattern file first and then using it with -f option to grep. Can I do this better? Any other better way I can write my over all logic.
Here's my script
#!/bin/bash
# List of error patterns to look for. Add more patterns to this list
p1='pattern1'
p2='pattern2'
p3='pattern3'
p4='pattern4'
PATTERNFILE=~/patternfile
FILETOCHECK=~/filetocheck
captureFileToCheck()
{
//appends data into filetocheck &
}
createPatternFile()
{
for i in `seq 100` # hopefully 100 is all we will need
do
if [ ! "x$p{$i}" = "x" ]
then
echo $p{$i} >> $PATTERNFILE
else
break
fi
done
}
createPatternFile
captureFileToCheck
while [ 1 ]
do
if grep -f $PATTERNFILE $FILETOCHECK
then
echo "something starting"
#doSometing
echo "something complete"
break
fi
done