Can someone help me edit the below script to make it run faster?
Shell: bash
OS: Linux Red Hat
The point of the script is to grab entire chunks of information that concerns the service "MEMORY_CHECK".
For each chunk, the beginning starts with "service {", and ends with "}".
I should point out that the status.log file is about 25MB.
grep -Pnw "MEMORY_CHECK" /apps/status.log | while read line
do
NUMP=$(echo $line | awk -F":" '{print $1}')
BEGINNINGA=$NUMP
BEGINNING=$(NUM=1
while [ $NUM -lt 70 ]
do
VAL=$NUMP
MINUSED=$(echo $VAL $NUM | awk '{print $1 - $2}')
DEFOU=$(sed -n ${MINUSED}p /apps/status.log | grep -Pv "#" | grep -P "service {")
if [ ! -z "$DEFOU" ] ; then
echo "${MINUSED}:$DEFOU" | awk -F":" '{print $1}'
break
fi
NUM=$(( $NUM + 1 ))
done)
##############################
END=$(NUM=1
while [ $NUM -lt 70 ]
do
VAL=$NUMP
MINUSED=$(echo $VAL $NUM | awk '{print $1 + $2}')
DEFOU=$(sed -n ${MINUSED}p /apps/status.log | grep -Pv "#" | grep -P "}")
if [ ! -z "$DEFOU" ] ; then
echo "${MINUSED}:$DEFOU" | awk -F":" '{print $1}'
break
fi
NUM=$(( $NUM + 1 ))
done)
echo "==================================================="
echo ""
BAD=$(sed -n ${BEGINNING},${END}p/apps/status.log | egrep "CRITICAL:|UNKNOWN:")
if [ ! -z "$BAD" ] ; then
sed -n ${BEGINNING},${END}p /apps/status.log | egrep "host_name=|check_command=|^plugin_output="
fi
echo ""
echo "==================================================="
done
