Shell scripting Quick notes for DBA's

To extract Oracle Home location from /etc/oratab :


#export ORACLE_HOME=`cat /etc/oratab|grep -v "^#"|cut -d: -f2 -s | grep db | head -1`  => If all DB are of same version
#export ORACLE_HOME=`cat /etc/oratab|grep -v "^#"| grep $db|cut -d: -f2 -s | head -1` => If Server has Different Versions of DB and get home Details using SID 

 

###################find SID's in Servers#############


ps -ef | grep "ora_smon"|grep -v grep|awk '{print $8}'|awk -F_ '{print$3}'


ps -ef|grep "ora_smon"|awk -F_ '{print$3}'|tail -1



ps -ef|grep "ora_smon"|awk -F '_' '{print$3}'|tail -1

 

ps -ef|grep smon|egrep -i -v '19|ASM|grep'|awk -F_ '{print $3}'


#################list Oracle HOme#################### 


grep "^$ORACLE_SID:" /etc/oratab|awk -F: '{print$2}'


##############List Oracle Version##################### 


grep -i "^$ORACLE_SID:" /etc/oratab | awk -F/ '{print$6}'


#################Check if the version is true or not ,no need for version number ################

################## for output of 1 the version is required one ########################

################## for output of 0 the version is not required one ####################


grep -i "^$ORACLE_SID:" /etc/oratab | grep -ic "12\.2" OR "12\.1"



grep -i "^CATALOG NAME:" $CATALOGFILE | awk -F ':' '{ print $1 }' | tail -1

 

strttm=`date +%s`
whoami
whoami
whoami
whoami
whoami
whoami
whoami
endtm=`date +%s`

Runtime=$( echo "$endtm - $strttm" )
hours=$((runtime / 3600)); minutes=$(( (runtime % 3600) / 60 )); seconds=$(( (runtime % 3600) % 60 ));
echo "Total execution Time : $hours:$minutes:$seconds "



SECONDS=0
    #
    # do stuff
    #
ELAPSED="Elapsed: $(($SECONDS / 3600))hrs $((($SECONDS / 60) % 60))min $(($SECONDS % 60))sec"


start=$SECONDS

... # do time consuming stuff

end=$SECONDS


echo "duration: $((SECONDS-start)) seconds elapsed.."


start=$(date +%s)
end=$(date +%s)
runtime=$(python -c "print '%u:%02u' % ((${end} - ${start})/60, (${end} - ${start})%60)")




#!/bin/bash
begin=$(date +"%s")

Script

termin=$(date +"%s")
difftimelps=$(($termin-$begin))
echo "$(($difftimelps / 60)) minutes and $(($difftimelps % 60)) seconds elapsed for Script Execution."



START_TIME=$SECONDS
dosomething
ELAPSED_TIME=$(($SECONDS - $START_TIME))


START_TIME=$SECONDS
# do something
sleep 65

ELAPSED_TIME=$(($SECONDS - $START_TIME))

echo "$(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec"    
#> 1 min 5 sec



Comments

Popular posts from this blog

Cold Backup Cloning of Database .

Find ALert log Location

FRA Usage and Administration