Operating System - HP-UX
1834935 Members
2280 Online
110071 Solutions
New Discussion

Re: Script is not working, need your help.

 
Gulam Mohiuddin
Regular Advisor

Script is not working, need your help.

This script is not working as expected; I should get an email if the error appears in the log.

The script runs every minute through CRON from 1 to 5 am.

The script works fine if I manually assign values for HRMM=01:00 variable, but will not work with runtime values.

The script returns a â 0â value even error exists.

#!/usr/bin/sh
LOGS=/psoft/hr88/appserv/RPHRMS/LOGS
HRMM=`date +%H:%M`
#HRMM=01:00
logdate=`date +%m%d`
mytime=0

mytime=`awk '/java.net.ConnectException/ && (substr($3,1,5) == "'"$HRMM"'") {n++}; END {print n+0}' $LOGS/APPSRV_${logdate}.LOG`

if [[ $mytime -ne 0 ]]; then
echo "WebServer is down"| mailx -s "WebServer Down $(date +%Y%m%d' '%H:%M)" gulam@peelsoft.ca
fi
exit 0



Thanks,

Gulam.
Everyday Learning.
7 REPLIES 7
Rodney Hills
Honored Contributor

Re: Script is not working, need your help.

I think the problem is in the way you are trying to use $HRMM in the awk command.

awk has an option -v to set a variable outside of the script so it can be used in the script.

You might try the following-
mytime=`awk -v HRMM=$HRMM '/java.net.ConnectException/ && (substr($3,1,5) == HRMM) {n++}; END {print n+0}' $LOGS/APPSRV_${logdate}.LOG`

HTH

-- Rod Hills
There be dragons...
Kent Ostby
Honored Contributor

Re: Script is not working, need your help.

Replace this:

mytime=`awk '/java.net.ConnectException/ && (substr($3,1,5) == "'"$HRMM"'") {n++}; END {print n+0}' $LOGS/APPSRV_${logdate}.LOG`


with this:

echo "HRMM " $HRMM > tmpfile
cat $LOGS/APPSRV_${logdate}.LOG >> tmpfile
awk '/HRMM/{myhrmm=$2;};/java.net.ConnectException/{if (substr($3,1,5) == myhrmm) {n++}; END {print n+0}' < tmpfile


"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Arturo Galbiati
Esteemed Contributor

Re: Script is not working, need your help.

Hi Gulam,
please add set -x at the topo of the script and post the output.
I don't think that the problem was the way you are using HRMM, because awk get it fine in both way:

/tmp/>HRMM=01:00
/tmp/>awk 'BEGIN {print "'"$HRMM"'"}' 01:00

/tmp/> HRMM=`date +%H:%M`
/tmp/>awk 'BEGIN {print "'"$HRMM"'"}' 04:12

HTH,
Art
Muthukumar_5
Honored Contributor

Re: Script is not working, need your help.

Script is fine. May be you can enable debugging in the script with set -x or set -v. what are you getting in that. I hope no data is available for that time frame.

Or change this line in script and try. Are you getting that mail atleast?

if [[ $mytime -ne 0 ]]; then
echo "WebServer is down"| mailx -s "WebServer Down $(date +%Y%m%d' '%H:%M)" gulam@peelsoft.ca
else
echo "WebServer is running fine" | mailx -s "WebServer is running fine $(date +%Y%m%d' '%H:%M)" gulam@peelsoft.ca
fi
--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Script is not working, need your help.

BTW,

HRMM=01:00

will not send mails b'cas no data availale in the log file to provide that. Try to change it as,

HRMM=01:12

will send mails.

--
Muthu
Easy to suggest when don't know about the problem!
Gulam Mohiuddin
Regular Advisor

Re: Script is not working, need your help.

Thanks everybody, this script is working now.

When I traced it with -x, I found that there was 1 minute difference between log messages and cron/system time. I changed my checking time one minute behind (-1) and everything starting working as expected.


Thanks,

Gulam.
Everyday Learning.
Gulam Mohiuddin
Regular Advisor

Re: Script is not working, need your help.

Thanks everybody.

Gulam.
Everyday Learning.