SAP instance check shell script

March 10, 2008

I wrote this script about about four years ago and came across it again today.  This will probobly be helpful in someway to someone someday ;)

This script requires the SAP SDK, which is available from SAP.  If you can’t find it let me know.

So, this script will do the following:

  • Attempt to connect to sap using sapinfo command check to see if host is already known to be down, or if recovered from being down

  • send pages / email to defined list

  • Tracks systems that are already down so as not to resend email / pages

And it may do more, or less.. I don’t know.  If you have suggestions or changes please email them to me at nick dot wilkens at gmail dot com.

#!/bin/sh
# N. Wilkens
# 8.26.04

# Location to sapinfo from sap SDK
SAPINFO=/usr/sapsdk/bin/sapinfo
#OVMSG=/opt/OV/bin/OpC/opcmsg

 

#SAP_HOST_FILE has the followinf format:
#<INSTANCE_NO> <SID> <CI_HOSTNAME> [OPTIONAL_APPSERVER HOSTNAMES.]

# EXAMPLE:

#00 PRD sapprod sapproda1 sapproda2 sapproda3
#01 CRP sapcrp

SAP_HOST_FILE=/usr/local/bin/SAP_HOSTS.PROD

 

MAILGRP=emailaddr

# function set_flag, creates a flag fil
function set_flag {
HOST=$1
STATUS=$2

case $STATUS in
DOWN)   touch /tmp/${HOST}.flag ;;
UP)     rm -f /tmp/${HOST}.flag ;;
*)      echo “Not supported”    ;;
esac
}

function send_alert {
HOST=$1
STATUS=$2

echo “${HOST} is ${STATUS}” |mailx -s “${HOST} is ${STATUS}” ${MAILGRP}
#${OVMSG}
}

# Check_Instance Function
function check_instance {
SYSNO=${1}; shift
SID=${1}; shift
HOST_LIST=${@}
for host in ${HOST_LIST}
do
# if the host is already know to be down, then skip.
if [ !${FLAGGED} ]
then
${SAPINFO} ashost=${host} sysnr=${SYSNO} >> /tmp/sapinfo.${host}

        # if the sapinfo command determines the host is not available, then
if [ $? -ne 0 ]
then
# IF the host flag file does not exist, then
if [ ! -e /tmp/${host}.flag ]
then
sleep 5
${SAPINFO} ashost=${host} sysnr=${SYSNO} >> /tmp/sapinfo.${host}
if [ $? -ne 0 ]
then
status=DOWN
set_flag $host $status
send_alert $host $status
#echo “${host} is down”
rm /tmp/sapinfo.${host}

                 #mv /tmp/sapinfo.${host} /tmp/sapinfo.${host}.$$  #useful for debugging problems
fi
#else
#   echo “$host still down”
fi
#else if the host is available..
else
if [ -e /tmp/${host}.flag ]
then
status=UP
set_flag $host $status
send_alert $host $status
#echo “${host} is up”
else
#echo “$host still up”
rm /tmp/sapinfo.${host}
fi
fi
else
echo “FLAGGED.. ”
fi
done
if [ -e dev_rfc ]
then
rm dev_rfc
fi
}

#usage: check_instance <SID_LIST> # as defined above
cat ${SAP_HOST_FILE} |while read HOST_LIST
do
check_instance $HOST_LIST &
done


Comments

One Response to “SAP instance check shell script”

  1. Paromita Ghosh on June 20th, 2008 11:24 am

    Hi,

    Could you tell me how SAP FI shell setup integrates with Payroll module?

    Thanks,

    Paromita

Got something to say?