Hiển thị các bài đăng có nhãn script. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn script. Hiển thị tất cả bài đăng

Thứ Sáu, 9 tháng 3, 2012

Shell Script for Checking whether SAP is Up or not

Wonder how would you check whether the SAP is up or not from Unix Shell Script. Here is a small shell script which uses the Enviornment variables and some files to check whether the SAP is runnig or not from the Operating System.

It can be automated and the output message can be used for sending as an Alert. It could be modified to suit any Landscape. In this case the command for running the script is "$/usr/bin/checksap.sh SID"


#!/bin/ksh
################################################################################
#
# /usr/bin/checksap.sh
# UNIX Shell Script for Checking
# 1. Whether SAP Has Started or not
# is found by checking whether kill.sap file exists or not
# and if it exists, whether the PID recorded in the file is live or not
# 2. Whether DB has started or notA
# is found using the Command R3trans -d
# 3. Whether SAP is able to detect the Message Server or not
# (important for Applicateion Server Test
# Creation Dated : 23/11/2006
# Authored by : Biju Kumar
#
################################################################################
__time=`date` ;
__date=`echo $__time | awk '{ printf "%s",$3$2$6"/"$4 ; }' ;`;
__variable='';
__variable1='';
SAPSYSTEMNAME=$1 #### 'D20';

LOCAL_FILE_NAME=`echo /usr/sap/${SAPSYSTEMNAME}/D*/work/kill.sap`;
my_SID_USERNAME=`echo ${SAPSYSTEMNAME}adm | tr '[A-Z]' '[a-z]'`
APPLICATION_SERVER="true" # Notes whether the SAP System has Application Servers or not ?

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 Running";
else
__variable1="$__time DB Inst Not Running";
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 Not Running ";
else
__variable=$__variable", CI is Running ";
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 started at $my_start_time /$__date";
fi;
else
__variable1="SAP Inst has not started /$__date";
fi;

__variable=$__variable", "$__variable1;
echo $__variable ;
##### It can be added to crontab, and scheduled to run maybe every 5 minutes. #####

Thứ Ba, 28 tháng 2, 2012

HPUX System Mirroring Script


This was taken off of itrc forums. It may need some adjustment.
#!/bin/ksh
PARTITION_FILE=/var/tmp/partition_file
# define primary and mirror disks
# the format is:
# PRI_DISK=cXtXdX
# PRI_DISK=cXtXdX
PRI_DISK=c2t1d0
MIR_DISK=c3t0d0
echo
echo “PRIMARY DISK = /dev/dsk/$PRI_DISK”
echo “MIRROR  DISK = /dev/dsk/$MIR_DISK”
echo
echo If the above is correct, hit enter to continue echo If not correct, hit control-C to quit echo
echo
echo “Creating partition file /tmp/$PARTITION_FILE”
echo
cat < $PARTITION_FILE
3
EFI 500MB
HPUX 100%
HPSP 400MB
EOF
# create system, OS and  service partitions
echo
echo idisk -wf $PARTITION_FILE /dev/rdsk/$MIR_DISK echo
idisk -wf $PARTITION_FILE /dev/rdsk/$MIR_DISK
# Create device files needed for the new partitions
insf -eC disk
# Verify the parition table
echo idisk /dev/rdsk/$MIR_DISK
idisk /dev/rdsk/$MIR_DISK
# Initialize the EFI partition for use
echo efi_fsinit -d /dev/rdsk/${MIR_DISK}s1 efi_fsinit -d /dev/rdsk/${MIR_DISK}s1
# Populate the /efi/hpux directory in the new EFI system partition
echo mkboot -e -l /dev/rdsk/$MIR_DISK
mkboot -e -l /dev/rdsk/$MIR_DISK
# Changing the auto file for the mirror to boot without quorum # Note: Using s1
echo “boot vmunix -lq”
echo “boot vmunix -lq”           > /tmp/AUTO.lq
efi_cp -d /dev/rdsk/${MIR_DISK}s1  /tmp/AUTO.lq   /EFI/HPUX/AUTO
# Verify the contents of the auto file on the primary and the mirror.
# Note: Using s1
echo  Verify the contents of the auto file on the primary and the mirror.
echo
efi_cp -d /dev/rdsk/${PRI_DISK}s1 -u  /EFI/HPUX/AUTO  /tmp/AUTO.pri efi_cp -d /dev/rdsk/${MIR_DISK}s1 -u  /EFI/HPUX/AUTO  /tmp/AUTO.alt
echo cat /tmp/AUTO.pri
echo
cat /tmp/AUTO.pri
echo cat /tmp/AUTO.alt
echo
cat /tmp/AUTO.alt
# add the new paritition to vg00
# Note: Using s2
echo  add the new paritition to vg00
echo  Note: Using s2
echo pvcreate  -B /dev/rdsk/${MIR_DISK}s2
pvcreate  -B /dev/rdsk/${MIR_DISK}s2
#pvcreate  -fB /dev/rdsk/${MIR_DISK}s2
vgextend vg00 /dev/dsk/${MIR_DISK}s2
# Add the new disk to /stand/bootconf
# Note: Using s2
echo  “Add the mirror disk $MIR_DISK to /stand/bootconf”
echo “l  /dev/dsk/${MIR_DISK}s2″ >> /stand/bootconf
echo  Mirroring all Logical Volumes in /dev/vg00, lvol1 – lvol8 echo echo
echo “Mirroring /stand”
echo lvextend -m 1 /dev/vg00/lvol1  /dev/dsk/${MIR_DISK}s2
lvextend -m 1 /dev/vg00/lvol1  /dev/dsk/${MIR_DISK}s2 echo
echo “Mirroring swap”
echo lvextend -m 1 /dev/vg00/lvol2  /dev/dsk/${MIR_DISK}s2
lvextend -m 1 /dev/vg00/lvol2  /dev/dsk/${MIR_DISK}s2 echo
echo “Mirroring root”
echo lvextend -m 1 /dev/vg00/lvol3  /dev/dsk/${MIR_DISK}s2
lvextend -m 1 /dev/vg00/lvol3  /dev/dsk/${MIR_DISK}s2 echo
echo “Mirroring /home”
echo lvextend -m 1 /dev/vg00/lvol4  /dev/dsk/${MIR_DISK}s2
lvextend -m 1 /dev/vg00/lvol4  /dev/dsk/${MIR_DISK}s2 echo
echo “Mirroring /opt”
echo lvextend -m 1 /dev/vg00/lvol5  /dev/dsk/${MIR_DISK}s2
lvextend -m 1 /dev/vg00/lvol5  /dev/dsk/${MIR_DISK}s2 echo
echo “Mirroring /tmp”
echo lvextend -m 1 /dev/vg00/lvol6  /dev/dsk/${MIR_DISK}s2
lvextend -m 1 /dev/vg00/lvol6  /dev/dsk/${MIR_DISK}s2 echo
echo “Mirroring /usr”
echo lvextend -m 1 /dev/vg00/lvol7  /dev/dsk/${MIR_DISK}s2
lvextend -m 1 /dev/vg00/lvol7  /dev/dsk/${MIR_DISK}s2 echo
echo “Mirroring /var”
echo lvextend -m 1 /dev/vg00/lvol8  /dev/dsk/${MIR_DISK}s2
lvextend -m 1 /dev/vg00/lvol8  /dev/dsk/${MIR_DISK}s2 echo