Skip to content

Commit 7d3a153

Browse files
committed
Optioon '-L' added to sqlplus call.
Use DB_CURRENT_ROLE file instead of select current role from database. File $DB_CURRENT_ROLE populated each minute by script check_db_role.sh
1 parent bb039ad commit 7d3a153

13 files changed

+81
-141
lines changed

app_listener_ctl.sh

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
#!/bin/bash
22

3-
# Guy Boulais, 2011/4/18
4-
# Anatoli Lyssak, 04/19/2011
5-
#
6-
# Script to start/stop listener LISTENER depending Primary/Standby database #
7-
83
#
94
# Setup environment from cron job
105
#
116
. /home/oracle/scripts/.bash_profile_cron $1 $2
127
export LISTENER=$3
138

14-
cd /home/oracle/scripts
9+
cd $WORKING_DIR
1510

1611
# Check if PMON is running
1712
if [ `ps -ef | grep ora_pmon_$ORACLE_SID | grep -v grep | wc -l` -eq 0 ]; then
@@ -30,14 +25,8 @@ fi
3025
echo "Oracle is running"
3126

3227
# Write current database role to variable
33-
CURRENT_ROLE=$(sqlplus -s / as sysdba <<EOF
34-
set feed off
35-
set head off
36-
set pages 0
37-
select DATABASE_ROLE from v\$database;
38-
exit
39-
EOF
40-
)
28+
CURRENT_ROLE=`cat $DB_ROLE_FILE`
29+
echo Current role: $CURRENT_ROLE
4130

4231
# Is it STANDBY?
4332
if [ "$CURRENT_ROLE" = "PHYSICAL STANDBY" ];
@@ -50,7 +39,7 @@ then
5039
lsnrctl stop $LISTENER
5140
echo "Listener $LISTENER stopped."
5241
else
53-
echo "Listener $LISTENER was not running."
42+
echo "Listener $LISTENER is not running."
5443
fi
5544
exit
5645
elif [ "$CURRENT_ROLE" = "PRIMARY" ];
@@ -62,7 +51,7 @@ then
6251
lsnrctl start $LISTENER
6352
echo "Listener $LISTENER started."
6453
else
65-
echo "Listener $LISTENER was running."
54+
echo "Listener $LISTENER is running."
6655
fi
6756
else
6857
echo "Can't find the database role to start/stop listener $LISTENER."

backup_archivelog.sh

+3-9
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@
44
. /home/oracle/scripts/.bash_profile_cron $1 $2
55

66
# Prepare log file name with time stamp
7-
LOG_FILE=/home/oracle/scripts/log/Arch_$1_$THE_TIME.log
7+
LOG_FILE=$WORKING_DIR/log/Arch_$1_$THE_TIME.log
88

99
# Write current database role to variable
10-
CURRENT_ROLE=$(sqlplus -s / as sysdba <<EOF
11-
set feed off
12-
set head off
13-
set pages 0
14-
select DATABASE_ROLE from v\$database;
15-
exit
16-
EOF
17-
)
10+
CURRENT_ROLE=`cat $DB_ROLE_FILE`
11+
echo Current role: $CURRENT_ROLE
1812

1913
# Is it PRIMARY?
2014
if [ "$CURRENT_ROLE" = "PRIMARY" ]

backup_diff.sh

+3-9
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@
44
. /home/oracle/scripts/.bash_profile_cron $1 $2
55

66
# Prepare log file name with time stamp
7-
LOG_FILE=/home/oracle/scripts/log/Diff_$1_$THE_TIME.log
7+
LOG_FILE=$WORKING_DIR/log/Diff_$1_$THE_TIME.log
88

99
# Write current database role to variable
10-
CURRENT_ROLE=$(sqlplus -s / as sysdba <<EOF
11-
set feed off
12-
set head off
13-
set pages 0
14-
select DATABASE_ROLE from v\$database;
15-
exit
16-
EOF
17-
)
10+
CURRENT_ROLE=`cat $DB_ROLE_FILE`
11+
echo Current role: $CURRENT_ROLE
1812

1913
# Is it PRIMARY?
2014
if [ "$CURRENT_ROLE" = "PRIMARY" ]

backup_full.sh

+3-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
cd /home/oracle/scripts
1616

1717
# Prepare log file name with time stamp
18-
LOG_FILE=/home/oracle/scripts/log/Full_$1_`date +%Y%m%d%H%M%S`.log
18+
LOG_FILE=$WORKING_DIR/log/Full_$1_`date +%Y%m%d%H%M%S`.log
1919

2020
# Check to see if there is any full backup running or not ?
2121
if [ `ps -ef | rep rman | grep "Full_$1" | grep -v grep | wc -l` -ne 0 ]
@@ -25,14 +25,8 @@ then
2525
fi
2626

2727
# Write current database role to variable
28-
CURRENT_ROLE=$(sqlplus -s / as sysdba <<EOF
29-
set feed off
30-
set head off
31-
set pages 0
32-
select DATABASE_ROLE from v\$database;
33-
exit
34-
EOF
35-
)
28+
CURRENT_ROLE=`cat $DB_ROLE_FILE`
29+
echo Current role: $CURRENT_ROLE
3630

3731
# Is it PRIMARY?
3832
if [ "$CURRENT_ROLE" != "PRIMARY" ];

check_db_role.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# * * * * * . /home/oracle/scripts/.bash_profile_cron dbname db_unique_name;/home/oracle/scripts/check_db_role.sh > /home/oracle/scripts/log/check_db_role_dbname.log
1010

1111
# Write current database role to variable
12-
CURRENT_ROLE=$(sqlplus -s / as sysdba <<EOF
12+
CURRENT_ROLE=$(sqlplus -L -s / as sysdba <<EOF
1313
set feed off
1414
set head off
1515
set pages 0

dbdown.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ echo "PMON for $ORACLE_SID is running"
2222
#*************************************************************
2323
# Test to see if Oracle is accepting connections
2424
#*************************************************************
25-
CHECK_OUTPUT0=$($ORACLE_HOME/bin/sqlplus -s / as sysdba <<!
25+
CHECK_OUTPUT0=$($ORACLE_HOME/bin/sqlplus -L -s / as sysdba <<!
2626
set feed off
2727
col instance_name for a15
2828
col status for a15

dbms_space_usage.sh

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
#!/bin/bash
2+
23
# Setup environment for cron job
34
. /home/oracle/scripts/.bash_profile_cron $1 $2
4-
cd /home/oracle/scripts
5+
6+
cd $WORKING_DIR
57

68
79

8-
REPORT=/home/oracle/scripts/reports/dbms_space_space_usage.txt
10+
REPORT=$WORKING_DIR/reports/dbms_space_space_usage.txt
911

1012
# Write current database role to variable
11-
CURRENT_ROLE=$(sqlplus -s / as sysdba <<EOF
12-
set feed off
13-
set head off
14-
set pages 0
15-
select DATABASE_ROLE from v\$database;
16-
exit
17-
EOF
18-
)
13+
CURRENT_ROLE=`cat $DB_ROLE_FILE`
14+
echo Current role: $CURRENT_ROLE
1915

2016
# Is it PRIMARY?
2117
if [ "$CURRENT_ROLE" = "PRIMARY" ]
2218
then
2319
echo "This is PRIMARY database. Let's run the report."
2420

25-
sqlplus -s "/ as sysdba" << EOF
21+
sqlplus -L -s "/ as sysdba" << EOF
2622
set serveroutput on
2723
2824
col fs4b format 999,999,999,999,999

load_space_history_daily.sh

+3-9
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,15 @@
1111
. /home/oracle/scripts/.bash_profile_cron $1 $2
1212

1313
# Write current database role to variable
14-
CURRENT_ROLE=$(sqlplus -s / as sysdba <<EOF
15-
set feed off
16-
set head off
17-
set pages 0
18-
select DATABASE_ROLE from v\$database;
19-
exit
20-
EOF
21-
)
14+
CURRENT_ROLE=`cat $DB_ROLE_FILE`
15+
echo Current role: $CURRENT_ROLE
2216

2317
if [ "$CURRENT_ROLE" = "PRIMARY" ];
2418
then
2519
echo "This is PRIMARY database."
2620

2721
#load stats
28-
sqlplus -s / as sysdba <<eof2
22+
sqlplus -L -s / as sysdba <<eof2
2923
set pages 0
3024
insert into dba_monitor.space_history_daily
3125
select trunc(sysdate) run_date,

populate_redo_volume_monitor.sh

+3-11
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,14 @@ fi
2626
echo "Oracle is running"
2727

2828
# Write current database role to variable
29-
CURRENT_ROLE=$(sqlplus -s / as sysdba <<EOF
30-
set feed off
31-
set head off
32-
set pages 0
33-
select DATABASE_ROLE from v\$database;
34-
exit
35-
EOF
36-
)
37-
38-
echo Role: $CURRENT_ROLE
29+
CURRENT_ROLE=`cat $DB_ROLE_FILE`
30+
echo Current role: $CURRENT_ROLE
3931

4032
# Is it PRIMARY?
4133
if [ "$CURRENT_ROLE" = "PRIMARY" ];
4234
then
4335
echo "This is PRIMARY database. Populate the table with data for the week."
44-
sqlplus -s / as sysdba <<eof
36+
sqlplus -L -s / as sysdba <<eof
4537
set pages 0
4638
set timing on
4739
insert into dba_monitor.day_redo_volume_gb

populate_ts_monitor.sh

+3-9
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,15 @@ fi
2323
echo "Oracle is running"
2424

2525
# Write current database role to variable
26-
CURRENT_ROLE=$(sqlplus -s / as sysdba <<EOF
27-
set feed off
28-
set head off
29-
set pages 0
30-
select DATABASE_ROLE from v\$database;
31-
exit
32-
EOF
33-
)
26+
CURRENT_ROLE=`cat $DB_ROLE_FILE`
27+
echo Current role: $CURRENT_ROLE
3428

3529
# Is it PRIMARY?
3630
if [ "$CURRENT_ROLE" = "PRIMARY" ];
3731
then
3832
echo "This is PRIMARY database. Insert data in the table."
3933

40-
sqlplus -s / as sysdba <<eof2
34+
sqlplus -L -s / as sysdba <<eof2
4135
set pages 0
4236
insert into dba_monitor.ts_mon
4337
(

sar_mem4excel.py

+30-38
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,41 @@
77
# or put it to config file;
88
#==========================================================#
99
import os
10+
import ConfigParser
1011
import re
11-
from datetime import datetime
1212
import fileinput
1313
import xlsxwriter
1414

15-
# HARD-CODED!!!
16-
sar_dir = '/var/log/sa'
17-
location = 'Seattle'
18-
# hostname = os.getenv('HOSTNAME')
19-
# Command above does not work from cron. It return 'None'.
20-
# But it works from command line.
21-
# It looks like os.getenv require some environment settings.
15+
# Open config file and read parameters
16+
# __file__ is a script name from command line.
17+
# Example: ./script.py or /full/path/to/the/script.py
18+
# os.path.splitext(__file__)[0] return __file__ without extention (.py);
19+
# .split('/')[-1] return string after last '/'
20+
script_name = os.path.splitext(__file__)[0].split('/')[-1]
21+
config_param = ConfigParser.RawConfigParser()
22+
config_param.read('./config/' + script_name + '.conf')
2223

2324
# Generate output file name
24-
timestamp = datetime.now().strftime("%Y%m%d")
25-
hostname = os.uname()[1]
26-
output_dir = '/home/oracle/scripts/Excel/'
27-
excel_file = output_dir + 'sar_mem4excel_' + location + '_' + hostname + '_' + timestamp + '.xlsx'
28-
column_headers = ('Date'
29-
,'Free Memory'
30-
,'Used Memore'
31-
,'Buffers'
32-
,'Cached'
33-
,'Free Swap'
34-
,'Used Swap'
35-
,'Swap Cad')
36-
workbook = xlsxwriter.Workbook(excel_file)
37-
worksheet_name = 'Memory Usage'
38-
worksheet = workbook.add_worksheet(worksheet_name)
39-
bold = workbook.add_format({'bold': 1})
40-
file_timestamp = ''
41-
column_headers_done = 0
42-
excel_data = []
43-
row_number = 0
25+
location = os.environ['GE0_LOCATION']
26+
hostname = os.uname()[1]
27+
excel_file = config_param.get('MEMORY', 'output_dir') + script_name + '_' + location + '_'+hostname + '_' + os.environ['THE_TIME'] + '.xlsx'
4428

45-
read_following_lines = 0
29+
# Setup spreadsheet
30+
file_timestamp = ''
31+
worksheet_name = 'Memory Usage'
32+
workbook = xlsxwriter.Workbook(excel_file)
33+
worksheet = workbook.add_worksheet(worksheet_name)
34+
bold = workbook.add_format({'bold': 1})
35+
column_headers = 0
36+
row_number = 0
37+
start_reading = 0
38+
excel_data = []
4639

4740
#-------------------------------------------#
4841
# Read SAR log files in chronological order #
4942
#-------------------------------------------#
5043
# go to SAR directory
51-
os.chdir(sar_dir)
44+
os.chdir(config_param.get('MEMORY', 'sar_dir'))
5245

5346
# List all files in this directory in chrono order
5447
all_sar_files = sorted(filter(os.path.isfile, os.listdir('.')), key=os.path.getmtime)
@@ -74,21 +67,20 @@
7467
# Start record the data
7568
if re.match('.*\skbmemfree\s.*', the_line):
7669
# Set the flag
77-
read_following_lines = 1
70+
start_reading = 1
7871
# Populate header once only
79-
if column_headers_done == 0:
80-
worksheet.write_row('A1', column_headers, bold)
81-
column_headers_done = 1
82-
#print column_headers
72+
if column_headers == 0:
73+
worksheet.write_row('A1', config_param.get('MEMORY','column_headers').split(','), bold)
74+
column_headers = 1
8375
continue
8476

8577
# Stop record the data
86-
if re.match('^Average.*', the_line) and read_following_lines == 1:
87-
read_following_lines = 0
78+
if re.match('^Average.*', the_line) and start_reading == 1:
79+
start_reading = 0
8880
continue
8981

9082
# Record the data
91-
if read_following_lines == 1:
83+
if start_reading == 1:
9284
# Skip all next headers
9385
if re.match('.*\skbmemfree\s.*', the_line):
9486
continue

0 commit comments

Comments
 (0)