Following shell
script will be helpful to automate the
startup of diagnostic agent in case it
is stopped.
You can schedule
the script as a crontab entry under the OS user that runs
diagnostic agent. The script will
perform the status check and if the
diagnostic agent is found stopped it will be automatically started by the
script. You will be able to overcome the
manual intervention needed.
Cron entry for
scheduling the script in every 5 minutes : */5 * * * *
/home/dadadm/check_diagnostic_agent.sh
In my case , DAD is the SID of the diagnostic agent. So
I have installed the script under the OS
user dadadm.
The script is not intended to replace standard SAP
process of starting the agent during OS startup.
If you observe that the agent does not start up during OS startup, check the following
1) whether
sapstartsrv service for the diagnostic agent has been configured in sapservices file. sapservices
can be located in /usr/sap directory
2)sapinit is
placed in /etc/init.d directory (this is for Linux systems)
3)Autostart parameter
has been set to 1 in instance profile of diagnostic agent
#SCRIPT STARTS HERE - COPY FROM THE LINE BELOW
#!/bin/sh
SID=""
profile_dir=""
LOG="$HOME/check_diagnostic_agent.log"
#DIR_LIBRARY=/usr/sap/DAD/SYS/exe/run
#=================================================================
startExecution()
{
start_timestamp=`date +"%Y-%m-%d %H:%M:%S"`
echo "[ Execution start timestamp: ${start_timestamp}" >>
"$LOG"
}
#=================================================================
exitOnError()
{
error_timestamp=`date +"%Y-%m-%d %H:%M:%S"`
echo "Execution end timestamp: ${error_timestamp} ]" >>
"$LOG"
exit 1
}
#=================================================================
endExecution()
{
end_timestamp=`date +"%Y-%m-%d %H:%M:%S"`
echo "Execution end timestamp: ${end_timestamp} ]" >>
"$LOG"
}
##################
##Main Function
startExecution
#================================================================
#Export Environment variables
if [ -f $HOME/.profile ]; then
.
$HOME/.profile
#echo
"Environment profile found..." >> "$LOG"
else
echo
"ERROR: No environment profile found!!!" >> "$LOG"
exitOnError
fi
#================================================================
#Check Environment variable SAPSYSTEMNAME
if [ ! -z $SAPSYSTEMNAME ]
then
SID="${SAPSYSTEMNAME}"
profile_dir="/usr/sap/${SAPSYSTEMNAME}/SYS/profile"
#echo "Diagnostic
agent SID id ${SAPSYSTEMNAME}" >> "$LOG"
else
echo "ERROR:
SAPSYSTEMNAME environment variable not found...exiting!!!" >>
"$LOG"
exitOnError
fi
#================================================================
#check whether startsap exists
STARTSAP_DIR=""
for dir in `echo $LD_LIBRARY_PATH | sed 's/:/ /g'`
do
if [ -x
"${dir}/startsap" ]
then
STARTSAP_DIR="$dir"
break
fi
done
#echo
"STARTSAP_DIR=${STARTSAP_DIR}"
if [ -z "$STARTSAP_DIR" ]
then
echo "ERROR:
startsap executable not found...exiting!!!" >> "$LOG"
exitOnError
fi
#=================================================================
#check if the SAP System is a diagnostic agent
if [ -d /usr/sap/$SAPSYSTEMNAME/SMDA[0-9][0-9] ]
then
echo "SAP
System ${SAPSYSTEMNAME} is a diagnostic agent..." >>
"$LOG"
else
echo "ERROR:
Dignostic agent is not installed..." >> "$LOG"
exitOnError
fi
#=================================================================
if [ -d "$profile_dir" ]
then
#echo "File
system /usr/sap/${SAPSYSTEMNAME}/SYS/profile exists..." >>
"$LOG"
echo
"Checking if diagnostic agent is running...." >>
"$LOG"
if [
`$STARTSAP_DIR/startsap check|grep -c "is running"` -ge 1 ]
then
# check
whether diagnostic agent processes are running
ps -ef | grep "/usr/sap/$SAPSYSTEMNAME/SMDA[0-9][0-9]/exe/jstart"
> /dev/null 2>&1
rc1=$?
ps -ef | grep
"/usr/sap/$SAPSYSTEMNAME/SMDA[0-9][0-9]/exe/sapstartsrv" >
/dev/null 2>&1
rc2=$?
rc=`expr $rc1
+ $rc2`
if [ $rc -eq
0 ]; then
echo "diagnostic
agent is already running..." >> "$LOG"
else
echo
"RC=$rc...Probably diagnostic agent is not running..Executing
startsap...." >> "$LOG"
$STARTSAP_DIR/startsap
fi
else
echo
"Probably diagnostic agent is not running..Executing startsap...."
>> "$LOG"
$STARTSAP_DIR/startsap
fi
else
echo "File
system does not /usr/sap/${SAPSYSTEMNAME}/SYS/profile exist..." >>
"$LOG"
exitOnError
fi
endExecution
# END OF SCRIPT