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. #####
Blog about SAP ERP especially on technical field such as SAP Basis/NetWeaver concepts, monitoring, administration, performance tuning, SAP Implementations, ABAP, Data Migration, OS, Database server, and FAQs
Showing posts with label script. Show all posts
Showing posts with label script. Show all posts
Saturday, March 10, 2012
Wednesday, February 29, 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=cXtXdX
# PRI_DISK=cXtXdX
PRI_DISK=c2t1d0
MIR_DISK=c3t0d0
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 “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
echo “Creating partition file /tmp/$PARTITION_FILE”
echo
cat < $PARTITION_FILE
3
EFI 500MB
HPUX 100%
HPSP 400MB
EOF
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
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
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
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
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
# 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
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.pri
echo cat /tmp/AUTO.alt
echo
cat /tmp/AUTO.alt
echo
cat /tmp/AUTO.alt
# add the new paritition to vg00
# Note: Using s2
# Note: Using s2
echo add the new paritition to vg00
echo Note: Using s2
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
# Note: Using s2
echo “Add the mirror disk $MIR_DISK to /stand/bootconf”
echo “l /dev/dsk/${MIR_DISK}s2″ >> /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 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 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 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 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 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 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 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
echo lvextend -m 1 /dev/vg00/lvol8 /dev/dsk/${MIR_DISK}s2
lvextend -m 1 /dev/vg00/lvol8 /dev/dsk/${MIR_DISK}s2 echo
Tuesday, July 12, 2011
Oracle Redo Log Generation
See how much redo logs you are generating per day. Good to use when you see your archivelog directories are filling up unusually.
This will not show you where the problem is though, will just give you the number of log switches and average MB generated per day so that you can compare day by day. If you do start seeing unusually high log switches, thus high volume of archivelog generation, maybe a good place to start is looking for transactions which do lots of UPDATE/DELETE operations in the STATSPACK.
I found this very nice SQL script on the Oracle website at this url :http://www.oracle.com/technology/oramag/code/tips2005/062705.html
Daily Count and Size of Redo Log Space (Single Instance)
SQL> SELECT A.*, Round(A.Count#*B.AVG#/1024/1024) Daily_Avg_Mb FROM ( SELECT To_Char(First_Time,'YYYY-MM-DD') DAY, Count(1) Count#, Min(RECID) Min#, Max(RECID) Max# FROM v$log_history GROUP BY To_Char(First_Time,'YYYY-MM-DD') ORDER BY 1 DESC ) A, ( SELECT Avg(BYTES) AVG#, Count(1) Count#, Max(BYTES) Max_Bytes, Min(BYTES) Min_Bytes FROM v$log ) B;
Sample Output:
DAY COUNT# MIN# MAX# DAILY_AVG_MB ---------- ---------- ---------- ---------- ------------ 2007-09-05 1 700 700 50 2007-09-04 1 699 699 50 2007-09-03 3 696 698 150 2007-09-02 2 694 695 100 2007-09-01 3 691 693 150 2007-08-31 4 687 690 200 2007-08-30 3 684 686 150 2007-08-29 2 682 683 100 2007-08-28 3 679 681 150 2007-08-27 3 676 678 150 2007-08-26 3 673 675 150
Hourly archivelog switches
There is another one which I find quite useful. I found it on the internet. I have also modified to show me a window of the last 7 days of the number of archivelog generation per hour (switches). I scripted it in unix so that shell sends me an email once a day with this log information. Very useful monitoring stuff!
SQL>SELECT to_date(first_time) DAY, to_char(sum(decode(to_char(first_time,'HH24'),'00',1,0)),'99') "00", to_char(sum(decode(to_char(first_time,'HH24'),'01',1,0)),'99') "01", to_char(sum(decode(to_char(first_time,'HH24'),'02',1,0)),'99') "02", to_char(sum(decode(to_char(first_time,'HH24'),'03',1,0)),'99') "03", to_char(sum(decode(to_char(first_time,'HH24'),'04',1,0)),'99') "04", to_char(sum(decode(to_char(first_time,'HH24'),'05',1,0)),'99') "05", to_char(sum(decode(to_char(first_time,'HH24'),'06',1,0)),'99') "06", to_char(sum(decode(to_char(first_time,'HH24'),'07',1,0)),'99') "07", to_char(sum(decode(to_char(first_time,'HH24'),'08',1,0)),'99') "08", to_char(sum(decode(to_char(first_time,'HH24'),'09',1,0)),'99') "09", to_char(sum(decode(to_char(first_time,'HH24'),'10',1,0)),'99') "10", to_char(sum(decode(to_char(first_time,'HH24'),'11',1,0)),'99') "11", to_char(sum(decode(to_char(first_time,'HH24'),'12',1,0)),'99') "12", to_char(sum(decode(to_char(first_time,'HH24'),'13',1,0)),'99') "13", to_char(sum(decode(to_char(first_time,'HH24'),'14',1,0)),'99') "14", to_char(sum(decode(to_char(first_time,'HH24'),'15',1,0)),'99') "15", to_char(sum(decode(to_char(first_time,'HH24'),'16',1,0)),'99') "16", to_char(sum(decode(to_char(first_time,'HH24'),'17',1,0)),'99') "17", to_char(sum(decode(to_char(first_time,'HH24'),'18',1,0)),'99') "18", to_char(sum(decode(to_char(first_time,'HH24'),'19',1,0)),'99') "19", to_char(sum(decode(to_char(first_time,'HH24'),'20',1,0)),'99') "20", to_char(sum(decode(to_char(first_time,'HH24'),'21',1,0)),'99') "21", to_char(sum(decode(to_char(first_time,'HH24'),'22',1,0)),'99') "22", to_char(sum(decode(to_char(first_time,'HH24'),'23',1,0)),'99') "23" from v$log_history where to_date(first_time) > sysdate -8 GROUP by to_char(first_time,'YYYY-MON-DD'), to_date(first_time) order by to_date(first_time) /
The output is like this:
DAY 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 --------- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- 31-AUG-07 1 1 1 1 2 1 1 1 1 1 1 2 0 1 0 1 0 1 1 0 1 0 1 1 01-SEP-07 0 1 1 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 1 1 1 02-SEP-07 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 2 1 1 1 1 03-SEP-07 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 1 1 2 04-SEP-07 1 1 2 1 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 2 05-SEP-07 2 1 2 1 2 2 1 2 1 2 2 1 2 2 1 2 2 2 1 2 2 2 2 2 06-SEP-07 2 1 2 2 2 2 1 2 2 2 2 2 1 2 2 1 0 2 0 0 0 0 1 0 07-SEP-07 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Saturday, July 2, 2011
How to generate Solman Key (without having Solman Server)
You might want to install SAP ECC 5 or SAP ECC 6 and been asking SolmanKey. What if you don't have Solman Server ? Then how would you generate solman key ? There are 2 ways (if you don't have Solman Server to generate solman key) :
1. Ask your friend which have Solman Server to generate it.
2. Use this simple script (VB Script) to generate it.
-------------------------------
''''''''''''''''''''''''''''''''''''''
' Solution Manager Key Generator '
'Save to SolManKeyGen.vbs and execute'
' '
''''''''''''''''''''''''''''''''''''''
'-------------------------------------------------------
Dim SIDs, SNs, SERVs, msg, ENDs, KEYs
msg="System ID (3 chr.)"
SIDs=InputBox(msg,"Solution Manager Key Generator")
msg="System Number (2 dig.)"
SNs=InputBox(msg,"Solution Manager Key Generator")
msg="Server Name (max. 15 chr.)"
SERVs=InputBox(msg,"Solution Manager Key Generator")
KEYs=SolManKeyGen(SIDs, SNs, SERVs)
msg="Solution Manager Key"
ENDs=InputBox(msg,"Solution Manager Key Generator",KEYs)
'-------------------------------------------------------
Function SolManKeyGen(SIDst, SNst, SERVst)
Dim SIDSNhex(5)
Dim SERVhex(15)
Dim reshex(5)
SIDSNstr = UCase(SIDst) + UCase(SNst)
SERVstr = UCase(SERVst)
For arrcnt = 1 To 5
SIDSNhex(arrcnt) = Asc(Mid(SIDSNstr, arrcnt, 1))
Next
For arrcnt = 1 To Len(SERVstr)
SERVhex(arrcnt) = Asc(Mid(SERVstr, arrcnt, 1))
Next
For arrcnt = Len(SERVstr) + 1 To 15
SERVhex(arrcnt) = 0
Next
If (Len(SERVstr) > 0) Then
If (Len(SERVstr) < 5) Then
For arrcnt = Len(SERVstr) + 1 To 5
SERVhex(arrcnt) = Asc(" ")
Next
End If
End If
If (Len(SERVstr) > 5) Then
If (Len(SERVstr) < 10) Then
For arrcnt = Len(SERVstr) + 1 To 10
SERVhex(arrcnt) = Asc(" ")
Next
End If
End If
If (Len(SERVstr) > 10) Then
If (Len(SERVstr) < 15) Then
For arrcnt = Len(SERVstr) + 1 To 15
SERVhex(arrcnt) = Asc(" ")
Next
End If
End If
For arrcnt = 1 To 5
reshex(arrcnt) = ((((0 Xor SIDSNhex(arrcnt)) Xor SERVhex(arrcnt)) Xor SERVhex(arrcnt + 5)) Xor SERVhex(arrcnt + 10))
Next
reshex(1) = reshex(1) Xor 84 Xor 0
reshex(2) = reshex(2) Xor 131 Xor 11
reshex(3) = reshex(3) Xor 194 Xor 46
reshex(4) = reshex(4) Xor 52 Xor 105
reshex(5) = reshex(5) Xor 119 Xor 188
hexstr = "0123456789ABCDEF"
resstr = ""
For arrcnt = 1 To 5
hihex = reshex(arrcnt) \ 16
lohex = reshex(arrcnt) Mod 16
resstr = resstr + Mid(hexstr, hihex + 1, 1) + Mid(hexstr, lohex + 1, 1)
Next
SolManKeyGen = resstr
End Function
-------------------------------
Copy this script to your Windows PC and save it as SolManKeyGen.vbs and then execute it.
Just like that....and shit, now you have solman key....
1. Ask your friend which have Solman Server to generate it.
2. Use this simple script (VB Script) to generate it.
-------------------------------
''''''''''''''''''''''''''''''''''''''
' Solution Manager Key Generator '
'Save to SolManKeyGen.vbs and execute'
' '
''''''''''''''''''''''''''''''''''''''
'-------------------------------------------------------
Dim SIDs, SNs, SERVs, msg, ENDs, KEYs
msg="System ID (3 chr.)"
SIDs=InputBox(msg,"Solution Manager Key Generator")
msg="System Number (2 dig.)"
SNs=InputBox(msg,"Solution Manager Key Generator")
msg="Server Name (max. 15 chr.)"
SERVs=InputBox(msg,"Solution Manager Key Generator")
KEYs=SolManKeyGen(SIDs, SNs, SERVs)
msg="Solution Manager Key"
ENDs=InputBox(msg,"Solution Manager Key Generator",KEYs)
'-------------------------------------------------------
Function SolManKeyGen(SIDst, SNst, SERVst)
Dim SIDSNhex(5)
Dim SERVhex(15)
Dim reshex(5)
SIDSNstr = UCase(SIDst) + UCase(SNst)
SERVstr = UCase(SERVst)
For arrcnt = 1 To 5
SIDSNhex(arrcnt) = Asc(Mid(SIDSNstr, arrcnt, 1))
Next
For arrcnt = 1 To Len(SERVstr)
SERVhex(arrcnt) = Asc(Mid(SERVstr, arrcnt, 1))
Next
For arrcnt = Len(SERVstr) + 1 To 15
SERVhex(arrcnt) = 0
Next
If (Len(SERVstr) > 0) Then
If (Len(SERVstr) < 5) Then
For arrcnt = Len(SERVstr) + 1 To 5
SERVhex(arrcnt) = Asc(" ")
Next
End If
End If
If (Len(SERVstr) > 5) Then
If (Len(SERVstr) < 10) Then
For arrcnt = Len(SERVstr) + 1 To 10
SERVhex(arrcnt) = Asc(" ")
Next
End If
End If
If (Len(SERVstr) > 10) Then
If (Len(SERVstr) < 15) Then
For arrcnt = Len(SERVstr) + 1 To 15
SERVhex(arrcnt) = Asc(" ")
Next
End If
End If
For arrcnt = 1 To 5
reshex(arrcnt) = ((((0 Xor SIDSNhex(arrcnt)) Xor SERVhex(arrcnt)) Xor SERVhex(arrcnt + 5)) Xor SERVhex(arrcnt + 10))
Next
reshex(1) = reshex(1) Xor 84 Xor 0
reshex(2) = reshex(2) Xor 131 Xor 11
reshex(3) = reshex(3) Xor 194 Xor 46
reshex(4) = reshex(4) Xor 52 Xor 105
reshex(5) = reshex(5) Xor 119 Xor 188
hexstr = "0123456789ABCDEF"
resstr = ""
For arrcnt = 1 To 5
hihex = reshex(arrcnt) \ 16
lohex = reshex(arrcnt) Mod 16
resstr = resstr + Mid(hexstr, hihex + 1, 1) + Mid(hexstr, lohex + 1, 1)
Next
SolManKeyGen = resstr
End Function
-------------------------------
Copy this script to your Windows PC and save it as SolManKeyGen.vbs and then execute it.
Just like that....and shit, now you have solman key....
Subscribe to:
Posts (Atom)