Skip to main content

Unix Script 1- to find the Zombee process and send email

####################################################################################################
# Script  - CATCHZ.ksh
# Author  - Amol P Ingle
# Date    - 5/24/2018
# Version - 1.0
#
# Purpose - when stack trace with infected 11 hits ASE dataserver it will check
#           1. Check Zombie process
#              -if Zombie process came in then will send alert message to DBA Team
#               with DBA Page to On-call DBA
#              - even if zombie process not in server and infected message comes in errorlog then-
#           2. Will check health of the ASE dataserver and send an email to DBA team
#           3. Will check message with shutdown as well and if comes then will
#              Alert email message to DBA Team and On-call DBA
#
#####################################################################################################

cd /dir

if test -f lerr1.txt
then
rm lerr1.txt
fi
rm tail.log
touch tail.log
touch /dir/SERVER_NAME.log_old
cp /SERVER_NAME/ASE_LOG/ASE-*/install/ /ASE-*/install/SERVER_NAME.log /dir/SERVER_NAME.log
diff /dir/SERVER_NAME.log /dir/SERVER_NAME.log_old | grep "<" > tail.log

#####################################################################################
# PART 1 - Check the zombie process if there or not
#
#####################################################################################

EMAILTEAM="abc@abc.com"

EMAILONCALL="xyz@abc.com"



for i in tail.log
do
grep infected $i >> lerr1.txt
done
file="lerr1.txt"

if [ -s "$file" ]
then
isql -UUser_Namedb_name.table_list -PXXXXXXXXX -Dmaster -w2000 << EOF!>catchzmb.log

IF EXISTS  (select spid from master..syslogshold slh where slh.spid <> 0 and slh.spid not in(select spid from master..sysprocesses))
PRINT 'Zombie Caught'
ELSE
PRINT 'NONE'
go
IF EXISTS (select spid from master..syslocks where spid not in (select spid from master..sysprocesses))
PRINT 'Zombie Caught'
ELSE
PRINT 'NONE'
go
exit
EOF!
fi

echo $(wc -l < lerr1.txt)> inftcount.txt
inft=`cat inftcount.txt`
grep Zombie catchzmb.log > rowsout.txt

grep Zombie catchzmb.log > rowsout.txt

if [ -s rowsout.txt ]
then

cat catchzmb.log > ZOMBIE.txt
  echo " Zombie Process Found, Please check SERVER_NAME" > ZOMBIE.txt
  echo " Infected Message count : $inft " > ZOMBIE.txt

 /usr/bin/mail -s "Zombie ALERT : Zombie Process Found on SERVER_NAME Server, Please check immediately" $EMAILONCALL < ZOMBIE.txt
else
echo "No Zombie Process"

fi
cp /dir/SERVER_NAME.log /dir/SERVER_NAME.log_old
rm rowsout.txt catchzmb.log ZOMBIE.txt




##########################################################################
## PART 2 - check infected 11 appears the check server health and email ##
##########################################################################

logfile="tail.log"


isql -UUser_Namedb_name.table_list -PXXXXXXXXX -Dmaster -w2000 <> health.log

print "<< StackTrace Message Appears on the Server Errolog, Checking server Health >>"
go
select @@servername,getdate()
go
print "<>"
go
select * from syslogshold where name not like '%replication_truncation_point%'
go
print "<< Blokcing on server>>"
go
select spid,cmd,blocked from sysprocesses where blocked >0
go
print "<<  SPID which is in syslogshold but not in sysprocesses >>"
go
select * from syslogshold where spid not in (select spid from master..sysprocesses ) and name not like '%replication_truncation_point%'
go
select spid from master..syslogshold slh where slh.spid <> 0 and slh.spid not in(select spid from master..sysprocesses)
go
print "<< SPID which is in syslocks but not in sysprocesses >>"
go
select spid from syslocks where spid not in (select spid from sysprocesses)
go
print "<< Below Database marked as Suspect / Offline Status >> "
go
select name from sysdatabases where status in (-32768,64,256,32)
go

exit
EOF1!
fi
/usr/bin/mail -s "StackTrace Message Appears on SERVER_NAME Server, See below details: Infected Message Count:$inft" $EMAILTEAM < health.log

rm health.log
#exit

#####################################################################################
# PART 3 - Check for the shutdown message
#
#####################################################################################

critical="tail.log"


cat $critical | grep "shutdown"
        if [ $? = 0 ]
        then

echo " shutdown message apprears in SERVER_NAME errorlog, Please check  server Health !!" > srvdown.txt

/usr/bin/mail -s "StackTrace made SERVER_NAME server down " $EMAILONCALL < srvdown.txt
/usr/bin/mail -s "StackTrace made SERVER_NAME server down " $EMAILTEAM < tail.log
fi
rm srvdown.txt inftcount.txt
exit

Comments

Popular posts from this blog

Undocumented DBCC commands in ASE

Introduction Undocumented DBCC commands: • DBCC BUFFER • DBCC BYTES • DBCC DBINFO • DBCC DBTABLE • DBCC DES • DBCC HELP • DBCC IND • DBCC LOG • DBCC PAGE • DBCC PROCBUF • DBCC PRTIPAGE • DBCC PSS • DBCC RESOURCE • DBCC TAB Literature Introduction In this article I want to tell you about some useful undocumented DBCC commands, and how you can use these commands in SQL Server 7.0 for administering and monitoring. DBCC is an abbreviation of a DataBase Consistency Checker. This is the description of DBCC from SQL Server Books Online: A statement used to check the logical and physical consistency of a database, check memory usage, decrease the size of a database, check performance statistics, and so on. Database consistency checker (DBCC) ensures the physical and logical consistency of a database, but is not corrective. Undocumented DBCC commands 1. DBCC BUFFER This command can be used to print buffer headers and pages from the buffer cache. Syntax: dbcc buffer ([dbid|dbname] ...

Replication Server Quick Ref Guide

Replication Server Guide : • Replication Server Commands • ASE commands and system stored procedures • ASE RSSD stored procedures • RSSD tables • Replication Server System Functions • Troubleshooting Tips Abbreviations Some abbreviations which are used in this Quick Reference Guide: ASE Adaptive Server Enterprise DSI DataServer Interface - RS thread for a connection to a replicate database DIST Distributor - RS thread per primary database LTM Log Transfer Manager; synonym for RepAgent RS, RepServer Replication Server RepAgent Replication Agent (in primary dataserver) RepDef Replication Definition RSI Replication Server Interface - RS thread related to a route to another RepServer RSM Replication Server Manager (a DBA tool normally used in combination with Sybase Central) RSSD Replication Server System Database SQM Stable Queue Manager - RS thread managing a queue SQT Stable Queue Manager - RS thread assembling transactions Replication Server Commands The following commands can only be ...

Interesting Notes on ASE

Some hidden things about ASE Different States of SLEEP When all processes are shown as SLEEPING by sp_who except the one, which issued the sp_who command, how can a user tell the difference between hangings versus running processes? Definitions In pre-4.9.2 SQL Servers, the output of sp_who could be difficult to interpret. Processes showed only one type of SLEEP status, "sleeping". In System 10, and 4.9.2 Rollup 2115 and above, sp_who shows four types of sleep along with the other possible statuses: Value Meaning Infected The server erred with a stack trace, and the process got an error that would normally kill it. The process is infected instead of killed. Background This process is in the background recv sleep The process is waiting for input from the client Send sleep The process is waiting for a write to the client to complete alarm sleep The process is waiting for an alarm (usually means the process is waiting for a wait for command to complete). Lock sleep The process i...