top of page
Search

SAP Hana Hyperwatch at OS level(Linux) Shell script

  • Writer: Kshitij Shrivastava
    Kshitij Shrivastava
  • Nov 15, 2022
  • 4 min read

################################################################################

# UNIX Shell Script for Checking

# 1. Whether SAP Has Started or not

# 2. Whether DB has started or not

# 3. Hyper watch

# Authored by : Kshitij Srivastava (kshitij.kumar.srivastava@sap.com)

#

################################################################################

__time=`date` ;

__date=`echo $__time | awk '{ printf "%s",$3$2$6"/"$4 ; }' ;`;

__variable='';

__variable1='';

SAPSYSTEMNAME=$1 #### 'D20';

RED='\033[0;31m'

GREEN='\033[0;32m'

NC='\033[0m'

LOCAL_FILE_NAME=`echo /usr/sap/${SAPSYSTEMNAME}/D*/work/kill.sap`;

my_SID_USERNAME=`echo ${SAPSYSTEMNAME}adm | tr '[A-Z]' '[a-z]'`

S_SID=`echo ${SAPSYSTEMNAME} | tr '[A-Z]' '[a-z]'`

APPLICATION_SERVER="true" # Notes whether the SAP System has Application Servers or not ?

rep='/tmp/report_'$SAPSYSTEMNAME'.html'

rm -fr /tmp/report.html

ci=`virtualip list |tail -1|column -t -s "." |awk '{print $1}'`

grep 'vhbyd'$S_SID'ci' /etc/sysconfig/network/virtualip -q && instance=ci

if test -r $instance

then

echo "***************************************************************" 2>&1

echo "ERROR: You have to run this script on the CI host with respective SID " 2>&1

echo "***************************************************************" 2>&1

echo "Aborting... " 2>&1

exit 1

fi


echo -e "<!DOCTYPE html>" >> $rep

echo -e "<html><style>table, th, td { border:1px solid black; }</style>" >> $rep

echo -e "<head>" >> $rep

echo -e "<meta http-equiv="Content-Type" content="text/html"; charset="utf-8">" >> $rep

echo -e "</head>" >> $rep

MY_PROC_LIST="";

MY_SAP_RUNNING='';

if [ -f $LOCAL_FILE_NAME ];

then

MY_PROC_LIST=`cat $LOCAL_FILE_NAME | awk '{printf $3}'`;

MY_SAP_RUNNING=`ps -p $MY_PROC_LIST | grep 'sapstart' | awk '{printf $4}'`;

fi;


MY_DBSERVER='true';


MY_DB_STR="";

if [ $MY_DBSERVER == "true" ] ;

then

MY_DB_STR=`su - $my_SID_USERNAME -c "R3trans -d" | grep "R3trans finished"| awk '{printf $3}'`;

fi;


__variable1='';

if [ $MY_DB_STR == "(0000)." ];

then

__variable1="$__time DB Inst `echo -e "${GREEN}Running...${NC}"`";

echo -e "<table style="width:100%"><tr><th colspan="2" style="background-color:#2980B9">$SAPSYSTEMNAME System Status</th></tr><tr><th style="background-color:#A9CCE3">Service Name</th><th style="background-color:#A9CCE3">Status</th></tr>

<tr><font color="green"><td>DataBase Instance</td><td> Running</td></font></tr>" >> $rep

else

__variable1="$__time DB Inst `echo -e "${RED}Not Running...${NC}"`";

echo -e "<table style="width:100%"><tr><th colspan="2" style="background-color:#2980B9">$SAPSYSTEMNAME System Status</th></tr><tr style="background-color:#A9CCE3"><th >Service Name</th><th style="background-color:#A9CCE3">Status</th></tr>

<tr><font color="red"><td>DataBase Instance</td><td> Not Running</td></font></tr>" >> $rep

fi;

__variable=$__variable" "$__variable1;


MY_ARGUMENT=`ps -ef | grep dw.sap | awk '{if (NR==1) printf $9}'`


if [ $APPLICATION_SERVER == "true" ];

then


my_var=`su - $my_SID_USERNAME -c "lgtst $MY_ARGUMENT" | grep "list of reachable "`;


if [ -z '$my_var' ];

then

__variable=$__variable", CI `echo -e "${RED}Not Running...${NC}"`";

echo -e "<tr><font color="red"><td>CenteralInstance</td><td> Not Running</td></font></tr>" >> $rep

else

__variable=$__variable", CI is `echo -e "${GREEN}Running...${NC}"`";

echo -e "<tr><font color="green"><td>CenteralInstance</td><td> Running fine</td></font></tr>" >> $rep

fi;

fi;


__variable1="";


if [ -f $LOCAL_FILE_NAME ]; #### -a [ $MY_SAP_RUNNING == "sapstart" ];

then

if [ $MY_SAP_RUNNING == "sapstart" ];

then

my_start_time=`ls -lt $LOCAL_FILE_NAME | awk '{ printf "%s",$7"-"$6"-2006 "$8 ; }' ;`;

__variable1="SAP Inst has `echo -e "${GREEN}started${NC}"` at $my_start_time / $__date";

echo -e "<tr><font color="green"><td>SAP Inst has</td><td> started</td></font></tr>" >> $rep

fi;

else

__variable1="SAP Inst has `echo -e "${RED}not started${NC}"` / $__date";

echo -e "<tr><font color="red"><td>SAP Instance has</td><td> Not Started</td></font></tr>" >> $rep

fi;


__variable=$__variable", "$__variable1;

echo -e "${GREEN}***********************SYSTEM STATUS*************************************************************************${NC}"

echo "$__variable"

inst=`su - $my_SID_USERNAME -c 'sapcontrol -nr 00 -function GetSystemInstanceList'>'/tmp/inst.txt'`

cat "/tmp/inst.txt" | column -t -s ","

echo -e "<tr><td>System Instance List</td> <td style="width:80%"><p style="background-color:Black"><font color="white"> `cat '/tmp/inst.txt'` </font></p></td></tr>" >> $rep

echo -e "${GREEN}***********************END OF SYSTEM STATUS******************************************************************${NC}"

echo -e "${GREEN}***********************ST22 Dump***********************************************************${NC}"

date="$(date +"%Y%m%d")"

dump='/tmp/dump.txt'

dump1='/tmp/dump1.txt'

sudo -i -u $my_SID_USERNAME hdbsql -jaxU DEFAULT -C "select count(distinct MODNO) from SNAP where DATUM='$date'" | sed '/row/d' > $dump

echo -e -n "Number of dumps today : "`cat $dump`

echo -e "<tr><td>Number of dumps today</td> <td>`cat $dump` </td></tr>" >> $rep


sudo -i -u $my_SID_USERNAME hdbsql -jaxU DEFAULT -C "select count(distinct MODNO) from SNAP where DATUM='$date' and FLIST like '%TSV%'" | sed '/row/d' > $dump1

echo -e -n "\nNumber of memory dumps today :" `cat $dump1`

echo -e "<tr><td>Number of memory dumps today</td> <td> `cat $dump1` </td></tr>" >> $rep


echo -e "${GREEN}\n***********************END OF ST22 Dump***********************************************************${NC}"

echo -e "${GREEN}***********************SAP LICENSE VALIDITY******************************************************************${NC}"

user=`w |grep sshd |awk '{ print $1 }'`

ssh -o StrictHostKeyChecking=no "$user"@'vhbyd'$S_SID'cs' 'sudo su - '$my_SID_USERNAME' -c " env SLIC_HW_VERSION="1" saplicense -get TRACE=2"' > '/tmp/SLIC.txt'

key=`cut -d " " -f 5 /tmp/SLIC.txt`


su - $my_SID_USERNAME -c "cdpro;saplikey pf='$SAPSYSTEMNAME'_ERS11_vhbyd'$S_SID'cs -show" > '/tmp/slen.txt'


find /tmp/slen.txt -type f -exec grep -h -2 -C7 "$key" {} + |column -t -s ":" > /tmp/fslic.txt


cat '/tmp/fslic.txt'

echo -e "<tr><td>SAP LICENSE VALIDITY</td> <td> `cat '/tmp/fslic.txt'|egrep -i 'Validity' |grep '[0-999999]'` </td></tr>" >> $rep


echo -e "${GREEN}***********************END OF SAP LICENSE VALIDITY***********************************************************${NC}"


echo -e "${GREEN}************************CPU USAGE****************************************************************************${NC}"

Cpu=`top -bn2 | grep '%Cpu' | tail -1 | grep -P '(....|...) id,'|awk '{print "CPU Usage: " 100-$8 "%"}'`

upc=`top -bn2 | grep '%Cpu' | tail -1 | grep -P '(....|...) id,'|awk '{print "Util: " 100-$8 "%"}'`>'/tmp/cpu.txt'

echo $Cpu;

echo -e "<tr><td>CPU Usage</td> <td>`top -bn2 | grep '%Cpu' | tail -1 | grep -P '(....|...) id,'|awk '{print "Utilization: " 100-$8 "%"}'`</td></tr>" >> $rep

echo -e "${GREEN}************************END CPU USAGE************************************************************************${NC}"

############################URL Count###############

echo -e "${GREEN}************************URL Status****************************************************************************${NC}"

sudo -i -u $my_SID_USERNAME hdbsql -jU DEFAULT "select TENANT_URL from TENANT" | sed '1d' | sed '$d' | sed '$d' | sed -e 's/"//g' | grep 'sap' > /tmp/urls.txt

filename='/tmp/urls.txt'

count=`wc -l ${filename}`

echo "Total number of URLs in the System : $count"

while read i; do

name=$(nslookup $i | grep Name | awk '{ print $2 }')

address=$(nslookup $i | grep Address | awk '{ print $2 }' | tail -1)

#echo "$i --------> $name : $address"

i="https://${i}"

STATUS=$(curl -s -o /dev/null -w "%{http_code}" $i)

ICM_STATE=$(curl -I -s $i | grep sap-icm | awk '{ print $2 }')

#STATUS=$(curl -s --head --request GET $i -x http://proxy:8080 | head -1 | awk '{ print $2 }')

if [ $STATUS == '302' ] || [ $STATUS == '200' ]; then

echo "$i ---> $name : $address ==== WORKING : HTTP$STATUS"

else

echo "$i ---> $name : $address ==== FAIL : HTTP$STATUS == ERROR:$ICM_STATE"

echo "$i is NOT UP , returned $STATUS ****" >> '/tmp/access.txt'

fi

done < $filename

count=`cat '/tmp/access.txt' |wc -l`

if [ $count -eq '0' ];then

echo -e "<tr><font color="green"><td>Tenants URLs Stauts </td> <td> All url are Accessible </td></font></tr>" >> $rep

else

echo -e "<tr><font color="red"><td>Tenants URLs Stauts </td> <td> <a>`cat '/tmp/access.txt'` </a></td></font></tr>" >> $rep

fi

`rm -fr '/tmp/access.txt'`

echo -e "${GREEN}************************END URL************************************************************************${NC}"

#################################################

#######################HANA DB Status#########################

echo -e "${GREEN}************************HANA DB****************************************************************************${NC}"

sudo -i -u $my_SID_USERNAME hdbsql -U DEFAULT "SELECT TOP 10 C.BACKUP_ID,C.ENTRY_TYPE_NAME,MIN(C.SYS_START_TIME),C.STATE_NAME AS STATUS,MAX(C.SYS_END_TIME),ROUND(SUM(F.BACKUP_SIZE)/1024/1024/1024,2) DB_SIZE_GB FROM SYS.M_BACKUP_CATALOG C, SYS.M_BACKUP_CATALOG_FILES F WHERE C.ENTRY_ID = F.ENTRY_ID AND (C.STATE_NAME = 'successful') and C.ENTRY_TYPE_NAME = 'differential data backup' or C.ENTRY_TYPE_NAME = 'complete data backup' group by C.BACKUP_ID, C.ENTRY_TYPE_NAME,C.STATE_NAME ORDER BY C.BACKUP_ID DESC" |sed '1d' | sed '/row/d'|sed '$d' | column -t -s ',' > '/tmp/sql.txt'


cat '/tmp/sql.txt'


echo -e "<tr><th colspan="2" style="background-color:#A9CCE3">Hana DB Status</th></tr>" >> $rep

echo -e "<tr><td>Hana Complete Backup</td> <td> `cat '/tmp/sql.txt'| grep -i 'complete'|head -1 |awk '{print $5,$6}'` </td></tr>" >> $rep

echo -e "<tr><td>Hana Differential Backup</td> <td> `cat '/tmp/sql.txt'| grep -i 'differential'|head -3 |awk '{print $5,$6}'` </td></tr>" >> $rep

echo -e "${GREEN}************************END HANA DB************************************************************************${NC}"

##############################################################

echo -e "<tr><th colspan="2" style="background-color:#A9CCE3">ICM Services</th></tr>" >> $rep

netstat -antp 2>/dev/null| grep 25000| grep icman &> /dev/null


if

[ $? == 0 ] ; then

echo -e "${GREEN}SMTP Service running fine${NC}"

echo -e "<tr><font color="green"><td>SMTP Service</td><td> Running</td></font></tr>" >> $rep

else


echo -e "${RED}SMTP Service not running${NC}" > /tmp/smtp.txt

echo -e "<tr><font color="red"><td>SMTP Service</td><td> Not Running</td></font></tr><br>" >> $rep

fi


netstat -antp 2>/dev/null| grep 50001| grep icman &> /dev/null


if

[ $? == 0 ] ; then

echo -e "${GREEN}HTTPS Service running fine${NC}"

echo -e "<tr><font color="green"><td>HTTPS Service</td><td> Running </td></font></tr>" >> $rep


else

echo -e "${RED}HTTPS Service not running${NC}" > /tmp/https.txt

echo -e "<tr><font color="red"><td>HTTPS Service</td><td>Not Running</td></font></tr>" >> $rep

fi

netstat -antp 2>/dev/null|grep 50000| grep icman &> /dev/null

if

[ $? == 0 ] ; then

echo -e "${GREEN}HTTP Service running fine${NC}"

echo -e "<tr><font color="green"><td>HTTP Service</td><td> Running</td></font></tr></table>" >> $rep

else


echo -e "${RED}HTTP Service not running${NC}" > /tmp/http.txt

echo -e "<tr><font color="red"><td>HTTP Service</td><td>Not Running</td></font></tr></table>" >> $rep

fi

echo -e "</html>" >> $rep

###############################

eid='DL_61320DFCA7AE7A0280E7D593@global.corp.sap'

attachFile="/tmp/allurls.txt"

(

echo To: "$eid"

echo From: "$SAPSYSTEMNAME"

echo "Content-Type: text/html;"

echo Subject: "System Status of $SAPSYSTEMNAME"

echo > "$attachFile"

echo `cat "$rep"`

) | sendmail -t


exit 0

 
 
 

Recent Posts

See All

Comments


Featured Posts
Check back soon
Once posts are published, you’ll see them here.
Recent Posts
Archive
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
CONTACT ME

Kshitij Shrivastava

SAP Basis CONSULTANT

Phone:

+91-706-661-4000

 

Email:

kshitij.sap@gmail.com 

  • Black LinkedIn Icon
  • Black Facebook Icon
  • Black Twitter Icon
  • Black Google+ Icon
  • Black Instagram Icon

Success! Message received.

© 2017 by Kshitij Shrivastava

bottom of page