-
Notifications
You must be signed in to change notification settings - Fork 0
/
clear_awr_miner.sh
executable file
·93 lines (85 loc) · 3.16 KB
/
clear_awr_miner.sh
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
###########################################################################
# Copyright (C) 2021 Gleb Otochkin
#
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>
###########################################################################
# Script to clean database and host names in the AWR miner output
# Created and tested on macOS
# Please take a backup copy of files
#
# MODIFIED (yyyy/mm/dd)
# Gleb Otochkin 2021/04/24 - added support for Solaris, Linux and Mac
usage() {
cat<<EOF
clear_awr_miner.sh: version 1.00
usage:
$0 [awr miner file *.out name] [new db name] [new hosts name]
awr miner file *.out name - file name to clean up (required)
new db name - new bogus database name (optional)
new hosts name - new bogus hosts name (optional)
EOF
}
if [[ $# -lt 1 ]] ; then
echo "Wrong number of arguments!"
usage
exit 1
fi
if [[ $# -lt 2 ]] ; then
db_new_name="ORADB"
else
db_new_name=$2
fi
if [[ $# -lt 3 ]] ; then
hosts_new="hostname"
else
hosts_new=$3
fi
if [[ $# -gt 3 ]] ; then
echo "Wrong number of arguments!"
usage
exit 1
fi
db_name=`grep DB_NAME $1 | awk '{print $2}'`
hosts=`grep HOSTS $1 | awk '{print $2}'`
PLATFORM=`uname`
case $PLATFORM in
Darwin)
db_name_lowcase=`echo $db_name | awk '{print tolower($0)}'`
db_new_name_lowcase=`echo $db_new_name | awk '{print tolower($0)}'`
echo $db_name $hosts $db_name_lowcase $db_new_name $db_new_name_lowcase
sed -i .bak "s/${db_name}/${db_new_name}/g" "$1"
sed -i .bak "s/${db_name_lowcase}/${db_new_name_lowcase}/g" "$1"
sed -i .bak "s/${hosts}/${hosts_new}/g" "$1"
rm "$1".bak
;;
SunOS)
db_name_lowcase=`echo $db_name | gawk '{print tolower($0)}'`
db_new_name_lowcase=`echo $db_new_name | gawk '{print tolower($0)}'`
echo $db_name $hosts $db_name_lowcase $db_new_name $db_new_name_lowcase
sed "s/${db_name}/${db_new_name}/g" "$1" > "$1".bak && cat "$1".bak > "$1"
sed "s/${db_name_lowcase}/${db_new_name_lowcase}/g" "$1" > "$1".bak && cat "$1".bak > "$1"
sed "s/${hosts}/${hosts_new}/g" "$1" > "$1".bak && cat "$1".bak > "$1"
rm "$1".bak
;;
Linux)
db_name_lowcase=`echo $db_name | awk '{print tolower($0)}'`
db_new_name_lowcase=`echo $db_new_name | awk '{print tolower($0)}'`
echo $db_name $hosts $db_name_lowcase $db_new_name $db_new_name_lowcase
sed -i "s/${db_name}/${db_new_name}/g" "$1"
sed -i "s/${db_name_lowcase}/${db_new_name_lowcase}/g" "$1"
sed -i "s/${hosts}/${hosts_new}/g" "$1"
;;
*)
echo "Unknown OS!"
;;
esac