I written following script to monitor two log files. First piece of code working fine, but piece is failing with followin error.
$ sh Log_Monitoring.sh
Database failed to written
4
Database failed to written
expr: syntax error
=================
clear
sh=`date | awk '{print $4}' | cut -d ":" -f1`
sm=`date | awk '{print $4}' | cut -d ":" -f2`
lh=`ls -l /opt/Heartbeat.log | awk '{print $8}' | cut -d ":" -f1`
lm=`ls -l /opt/Heartbeat.log | awk '{print $8}' | cut -d ":" -f2`
if [ x = 0 ]
then
if [ -f "/export/home/paven/interval_core.dat" ]; then
echo "0" > /export/home/paven/interval_core.dat
fi
else
x=`cat /export/home/paven/interval_core.dat`
if [ "$sh" = "$lh" ]
then
if [ "$sm" = "$lm" ]
then
echo "Database writting properly"
echo "0" > /export/home/paven/interval_core.dat
else
echo "Database failed to written"
x=`expr $x + 1`
echo "$x" > /export/home/paven/interval_core.dat
echo $x
if [ "$x" = "2" ]
then
#mailx -s "Data base failed to write in Core Environment - Need to retrieve missing data" -c "xyz@abc.com"<<EOF
echo Data base failed to write in Core Environment - Need to retrieve missing data
fi
fi
fi
fi
sleep 10
sh1=`date | awk '{print $4}' | cut -d ":" -f1`
sm1=`date | awk '{print $4}' | cut -d ":" -f2`
lh1=`ls -l /opt/NH_Heartbeat.log | awk '{print $8}' | cut -d ":" -f1`
lm1=`ls -l /opt/NH_Heartbeat.log | awk '{print $8}' | cut -d ":" -f2`
if [ y = 0 ]
then
if [ -f "/export/home/paven/interval_NH.dat" ]; then
echo "0" > /export/home/paven/interval_NH.dat
fi
else
y=`cat /export/home/paven/interval_NH.dat`
if [ "$sh1" = "$lh1" ]
then
if [ "$sm1" = "$lm1" ]
then
echo "Database writting properly"
echo "0" > /export/home/paven/interval_NH.dat
else
echo "Database failed to written"
y=`expr $y + 1`
echo "$y" > /export/home/paven/interval_NH.dat
echo $y
if [ "$y" = "2" ]
then
#mailx -s "Data base failed to write in NHS Environment - Need to retrieve missing data" -c "xyz@abc.com"<<EOF
echo Data base failed to write - Need to retrieve missing data
fi
fi
fi
fi
================