Protected: Unix Shell Scripting For DBA’s (PART – 01)
There is no excerpt because this is a protected post.
There is no excerpt because this is a protected post.
Oracle : Scheduling crontab to send EMAIL in Unix $ vi test.bash
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#!/bin/bash #Script to perform testing ## Environment variables TODAY=`date +%d-%b-%Y-%H:%M:%S` export ORACLE_HOME='/u01/app/oracle/product/12102' export ORACLE_SID='ORCL' export ORACLE_BASE='/u01/app/oracle' export PATH=$PATH:${ORACLE_HOME}/bin export MAILIST='ktexperts@gmail.com' export LOG='/tmp/test_mig.log' #Function to trigger email function mailog { cat ${LOG} | mailx -s "${TODAY} - TEST Mail" ${MAILIST} } #Function step1 function step1 { echo " " >> $LOG echo "Started Step 1" >> $LOG echo " " >> $LOG echo "Test email " >> $LOG sqlplus -s /nolog <<START >>$LOG Connect / as sysdba set serveroutput on set timing on prompt Todays date select sysdate from dual; START echo " " >> $LOG echo "----- END OF Step1 ------" >> $LOG } #Script execution is here > $LOG if [ "$#" -eq 0 ] then step1 mailog else $1 mailog fi |
Crontab entry
|
1 |
00 02 * * * /local/home/oracle/test.bash 1>/local/home/oracle/test.cronlog 2>/local/home/oracle/test.cronerr |
Updated Script.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
#!/bin/bash #Script to perform testing ## Environment variables TODAY=`date +%d-%b-%Y-%H:%M:%S` export ORACLE_HOME='/u01/app/oracle/product/12.1.0.2' export ORACLE_SID='prod' export ORACLE_BASE='/u01/app/oracle' export PATH=$PATH:${ORACLE_HOME}/bin export MAILIST='ktexperts@gmail.com' export LOG='/tmp/test_mig.log' #Function to trigger email function mailog { cat ${LOG} | mailx -s "${TODAY} - TEST Mail" ${MAILIST} } #Function step1 function step1 { echo " " >> $LOG echo "Started Step 1" >> $LOG echo " " >> $LOG echo "Test email " >> $LOG sqlplus vinod/vinod <<START >>$LOG prompt updating records in EMP table select * from emp where deptno=20; prompt update emp set sal=sal+500 WHERE deptno=20; update emp set sal=sal+500 WHERE deptno=20; prompt select * from emp where deptno=20; select * from emp; START echo " " >> $LOG echo "----- END OF Step1 ------" >> $LOG } #Script execution is here > $LOG if [ "$#" -eq 0 ] then step1 mailog else $1 mailog fi |
Crontab entry
|
1 |
02 * * * * /home/oracle/test.bash 1>/home/oracle/test.cronlog 2>/home/oracle/test.cronerr |
Hello Readers I Standardized and customized the SecureCRT to group and link the frequently used commands. It will make the Oracle DBA job easy and fast. Download SecureCRT Software binaries using below link. https://www.vandyke.com/cgi-bin/account_login.php?pid=scrt_x64_870 Or Download SecureCRT binaries from Google Drive https://drive.google.com/file/d/1jfGtmKKwPwmOcjO1t5BJoN_b77V09a_q/view?usp=sharing Let me know… Read More
Oracle : Generate Clear output for crs_stat -t
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
cat crsstat.sh #!/bin/bash RSC_KEY=$1 QSTAT=-u AWK=/bin/awk # if not available use /usr/bin/awk # Table header:echo "" $AWK \ 'BEGIN {printf "%-55s %-10s %-18s\n", "HA Resource", "Target", "State"; printf "%-55s %-10s %-18s\n", "-----------", "------", "-----";}' # Table body: ORA_CRS_HOME=/u01/app/grid/product/12102 $ORA_CRS_HOME/bin/crs_stat $QSTAT | $AWK \ 'BEGIN { FS="="; state = 0; } $1~/NAME/ && $2~/'$RSC_KEY'/ {appname = $2; state=1}; state == 0 {next;} $1~/TARGET/ && state == 1 {apptarget = $2; state=2;} $1~/STATE/ && state == 2 {appstate = $2; state=3;} state == 3 {printf "%-55s %-10s %-18s\n", appname, apptarget, appstate; state=0;}' |
chmod 755 crsstat.sh Output :
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
./crsstat.sh HA Resource Target State ----------- ------ ----- ora.CRS01.dg ONLINE ONLINE on server11 ora.DATA01.dg ONLINE ONLINE on server11 ora.FRA01.dg ONLINE ONLINE on server11 ora.LISTENER.lsnr ONLINE ONLINE on server11 ora.LISTENER_SCAN1.lsnr ONLINE ONLINE on server12 ora.LISTENER_SCAN2.lsnr ONLINE ONLINE on server11 ora.LISTENER_SCAN3.lsnr ONLINE ONLINE on server11 ora.MGMTLSNR ONLINE ONLINE on server11 ora.REDO01.dg ONLINE ONLINE on server11 ora.REDO02.dg ONLINE ONLINE on server11 ora.asm ONLINE ONLINE on server11 ora.cvu ONLINE ONLINE on server11 ora.mgmtdb ONLINE ONLINE on server11 ora.net1.network ONLINE ONLINE on server11 ora.oc4j ONLINE ONLINE on server11 ora.ons ONLINE ONLINE on server11 ora.orcl2.vin_svc_node1.svc ONLINE ONLINE on server11 ora.orcl2.vin_svc_node2.svc ONLINE ONLINE on server11 ora.scan1.vip ONLINE ONLINE on server12 ora.scan2.vip ONLINE ONLINE on server11 ora.scan3.vip ONLINE ONLINE on server11 ora.server11.ASM1.asm ONLINE ONLINE on server11 ora.server11.LISTENER_server11.lsnr ONLINE ONLINE on server11 ora.server11.ons ONLINE ONLINE on server11 ora.server11.vip ONLINE ONLINE on server11 ora.server12.ASM2.asm ONLINE ONLINE on server12 ora.server12.LISTENER_server12.lsnr ONLINE ONLINE on server12 ora.server12.ons ONLINE ONLINE on server12 ora.server12.vip ONLINE ONLINE on server12 |
MySQL MySQL belongs to relational database management system (RDBMS Software). MySQL is one of the most widely using open source relational database. MySQL was started developing by Michael Widenius “Monty” in the year 1979. At that time it named as UNIREG. It’s an in-house database tool… Read More
Dear Readers, In this article we will see Cassandra Data distribution and replication. Cassandra is a Distributed NoSQL database means all the data is distributed across the Cluster. in Cassandra data distribution and replication go together. The distribution and replication depending on the partition key,… Read More
Dear Readers, In this article, we will see the Data Masking in Oracle 12c. Every organization maintains the sensitive data regarding their operations. like personal identifiable data, personal sensitive data or commercially sensitive data. organizations are required to protect their sensitive data falling to the wrong… Read More
Dear Readers, In this article, we will see the 12CR2 SQL*PLUS History Command In version 12CR2 Oracle introduced the history command which helps the users to reissue the previously executed commands. Which decreases the time to write the repeated syntaxes every time. By default the… Read More
Note : Please test below steps in your lower environment before trying in Production Backup of GI and RDBMS home before patching As root do it when DB instance/CRS is down :
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
-- -- As root do it when DB instance/CRS is down : 1) For GRID Home : [grid@server1 ~]$ cd /u01/app/grid/product [grid@server1 product]$ ls -ltr total 4 drwxr-x---. 75 root oinstall 4096 Feb 13 02:23 12102 [grid@server1 product]$ sudo su - root cd /u01/app/grid/product tar -czvf bkup_GI_home_12102.tar.gz ./12102 2) For RDBMS Home : $ pwd /u01/app/oracle/product oracle@server1:ORCL:/u01/app/oracle/product> $ ls -ltr total 6222468 -rw-r--r--. 1 oracle oinstall 6371799040 Mar 25 23:59 12102_bkp.tar drwxr-xr-x. 72 oracle oinstall 4096 Mar 26 03:13 12102 oracle@server1:ORCL:/u01/app/oracle/product> sudo su - root cd /u01/app/oracle/product tar -czvf bkup_rdbms_home_12102.tar.gz ./12102 3) For oraInventory : /var/opt/grid/oraInventory As root : tar -czvf oraInventory_Jun27.tar.gz ./oraInventory -- -- |
Restore : If any issues and needs to restore… Read More
Dear Readers, In this article, we will see the TOP N QUERIES in Oracle 12c 12c Introduced the Top-N queries concept to fetch required rows by writing the simple queries. Top-N queries provide a method for limiting the result to a specific number of rows.… Read More