forked from daniel8192/oracle_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_exadata_passwords.sh
186 lines (172 loc) · 5.46 KB
/
set_exadata_passwords.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
#########################################################
# #
# change all passwords of one exadata #
# #
#########################################################
# #
# v0.1 11/2016 Hillinger start script #
# #
# possible expantions #
# change grup password #
# #
#########################################################
#set -x
#read password from stdin
read -p "Enter password:" password1
read -p "Enter password again:" password2
if [ "$password1" = "$password2" ] && [ ${#password1} -ge 8 ]
then
password="$password1"
unset password1 password2
else
echo "Passowrd missmatch or less then 8 chars" 1>&2
exit 1
fi
#find exadata prefix
db="$(hostname -s)"
cel="$(getent hosts $(cut -d \" -f2 /etc/oracle/cell/network-config/cellip.ora |cut -d \; -f1 |tail -1) |awk '{ print $2 } ')"
exa_prefix="$(for i in `seq 1 ${#db}` ; do if [ "${db:$i-1:1}" = "${cel:$i-1:1}" ]; then printf "${db:$i-1:1}" ; else break; fi; done)"
unset db cel
#collect information about the exadata components
dbnodes="$(olsnodes)"
cells="$(cut -d \" -f2 /etc/oracle/cell/network-config/cellip.ora |cut -d \; -f1|xargs -n1 getent hosts|awk '{print $2}' |cut -d '-' -f 1)"
switches="$(ibswitches |grep $exa_prefix |awk '{print $10}')"
pdus="$(getent hosts ${exa_prefix}{sw-pdu,p,-pdu}{a,b}{0,1,}{0,1,} |awk '{print $2}'|sort -u)"
#define user which should be changed
dbnode_users="root oracle"
cell_users="root celladmin cellmonitor"
ilom_users="root oemuser MSUser"
ib_users="root nm2user ilom-admin ilom-operator"
asm_users="sys asmsnmp"
pdu_user="admin"
#env
ssh_opts="-o StrictHostKeyChecking=no"
echo "GRUB password will not be changed! Not needed!"
#on all computing nodes
for i in $dbnodes
do
echo "changing passwords on $i "
ssh $ssh_opts $i "for user in $dbnode_users
do
echo -en \"\t\t\${user}\"
echo \"\${user}:${password}\" | chpasswd -c SHA512
if [ $? -eq 0 ]
then
echo \"... SUCCESS\"
else
echo -e \"... \e[1;31mERROR\e[0m\"
fi
done"
done
#on all cells
for i in $cells
do
echo "changing passwords on $i "
ssh $ssh_opts $i "for user in $cell_users
do
echo -en \"\t\t\${user}\"
echo \"\${user}:${password}\" | chpasswd -c SHA512
if [ $? -eq 0 ]
then
echo \"... SUCCESS\"
else
echo -e \"... \e[1;31mERROR\e[0m\"
fi
done"
done
# change password on iloms
for i in $dbnodes $cells
do
echo "changing ilom passwords on $i "
ssh $ssh_opts $i "for user in $ilom_users
do
echo -en \"\t\t\${user}\"
ipmitool sunoem cli \"set -script /SP/users/\${user} password=${password}
${password}
\" &>/dev/null
if [ $? -eq 0 ]
then
echo \"... SUCCESS\"
else
echo -e \"... \e[1;31mERROR\e[0m\"
fi
done"
done
#change asm password
echo "changing asm passwords "
su - grid -c "for user in $asm_users
do
echo -en \"\t\t\${user}\"
echo -e \"alter user \${user} identified by \"${password}\";\" |sqlplus -S / as sysasm|grep -q \"User altered.\"
if [ $? -eq 0 ]
then
echo \"... SUCCESS\"
else
echo -e \"... \e[1;31mERROR\e[0m\"
fi
done"
#change password on infiniband switches
for i in $switches
do
echo "changing ib passwords on $i"
ssh $ssh_opts $i "for user in $ib_users
do
echo -en \"\t\t\${user}\"
echo \"\${user}:${password}\" | chpasswd -c SHA512
if [ $? -eq 0 ]
then
echo \"... SUCCESS\"
else
echo -e \"... \e[1;31mERROR\e[0m\"
fi
done"
done
#change pdu passwords
for i in $pdus
do
echo "changing pdu passwords on $i"
curl https://${i} &>/dev/null
if [ $? -eq 7 ] #pdu version prior 2
then
for x in {1..3}
do
read -p "Enter current pdu password: " old_password
if ( ! curl "http://${i}/getUser.cgi?user=${pdu_user}&pass=${old_password}" 2>/dev/null |grep -q "<title>Login</title>" )
then
curl "http://${i}/addUserPass.cgi?US1=${pdu_user}&PA1=${password}&PO1=2" 2>/dev/null |grep -q "<title>Net Configuration / Firmware Update / Module Info </title>"
if [ $? -eq 0 ]
then
echo "... SUCCESS"
else
echo -e "... \e[1;31mERROR\e[0m"
fi
curl "http://${i}/logout.cgi?logout=Logout" &>/dev/null
break;
else
echo "not able to login to PDU"
[ $x -eq 3 ] && echo -e "... \e[1;31mERROR\e[0m"
fi
done
else # pdu version 2 or higher
for x in {1..3}
do
read -p "Enter current pdu password: " old_password
if ( ! curl --insecure -X POST -d "User=${pdu_user}&Pass=${old_password}" https://${i}/Login.cgi 2>/dev/null |grep -q "url=Login.htm" )
then
curl --insecure -X POST -d "HttpU1=${pdu_user}&HttpP1=${password}&HttpP1R=${password}&HttpR1=2" https://${i}/Http_Access.cgi 2>/dev/null|grep -q "url=Http_Access.htm"
if [ $? -eq 0 ]
then
echo "... SUCCESS"
else
echo -e "... \e[1;31mERROR\e[0m"
fi
curl --insecure -X POST https://${i}/Logout.cgi &>/dev/null
break;
else
echo "not able to login to PDU"
[ $x -eq 3 ] && echo -e "... \e[1;31mERROR\e[0m"
fi
done
fi #end if version
done