Shell script for kill Sap Serivces from multiple servers
- Kshitij Shrivastava
- Nov 15, 2022
- 1 min read
#!/bin/bash
###############################################################################
#Script Name : kill sidadm sap process
#Description : kill sidadm sap process
#Author : Kshitij Kumar Srivastava
#Email : kshitj.sap@gmail.com
################################################################################
grep 'vaci' /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 " 2>&1
echo "***************************************************************" 2>&1
echo "Aborting... " 2>&1
exit 1
fi
echo "enter SID"
read SID
sid=$(echo "$SID" | tr '[:upper:]' '[:lower:]')
SID=$(echo "$SID" | tr '[:upper:]' '[:lower:]')
echo "enter File with path"
read file
grep "$sid" /etc/sysconfig/network/virtualip -q && match=yes
if test -r $match
then
echo "***************************************************************" 2>&1
echo "ERROR: SID do not match with the current CI server " 2>&1
echo "***************************************************************" 2>&1
echo "Aborting... " 2>&1
exit 1
fi
count=`cat $file | wc -l`
match_count=`grep $sid $file |wc -l`
pas=`sudo su - ${sid}adm -c 'sapcontrol -nr 00 -function GetSystemInstanceList | grep GREEN | grep ABAP | wc -l' > /tmp/sap.txt`
#pas=`sudo -i ps -eaf |grep hostctrl |wc -l` > /tmp/sap.txt
#sap=`cat /tmp/sap.txt`
sap=`cat /tmp/sap.txt |grep -o '[0-99]*' |tail -1`
if [ "$sap" -eq "0" ]
then
{
echo -n "The apps are stopped killing the process now in mentioned servers. Do you wish to proceed?(Y/N):"
cat $file
read response
response=`echo $response | tr '[a-z]' '[A-Z]'`
if [ "$response" != "N" ];
then
for i in `cat ${file}`;
do
echo "*************************** '$i' ****************************"
ssh -o StrictHostKeyChecking=no $i sudo -i kill `ssh -o StrictHostKeyChecking=no $i "sudo su -c 'pgrep -f hostctrl && pgrep -f sapstartsrv && pgrep -f DAA'"`;
done
else
echo "**************************************************************"
echo "Aborting... "
exit 1
fi
}
else
echo "The apps are running please stop the apps then kill process"
fi
Recent Posts
See All################################################################################ # UNIX Shell Script for Checking # 1. Whether SAP Has...
Comments