-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathcreateuser
executable file
·167 lines (142 loc) · 3.03 KB
/
createuser
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
#!/bin/bash
#
# Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
#
# Licensed under the Universal Permissive License v 1.0 as shown
# at http://oss.oracle.com/licenses/upl
#
declare -r dfltDSN="sampledb"
declare sname=`basename "$0"`
declare username=""
declare password=""
declare dsn="${dfltDSN}"
declare connstr=""
declare dir=""
usage()
{
echo
echo "Usage:"
echo
echo " ${sname} [-dsn dsn]"
echo
echo "Creates a database user in the database referenced by the specified"
echo "DSN (or the default DSN 'sampledb' if not specified)."
echo
echo "You will be prompted for the name of the user to be created and the"
echo "password to be assigned to them."
echo
echo "Users can only be created by the instance administrator user"
echo "via a direct mode connection."
echo
exit 99
}
warnUser()
{
local a
echo
echo "Users can only be created by the instance administrator user"
echo "via a direct mode connection."
echo
echo "If these criteria are satisfied then press enter to proceed otherwise"
echo "press Ctrl-C to interrupt:"
read a
echo
return 0
}
getString()
{
local msg="$1"
local str=""
while [ "${str}" == "" ]
do
if [ "${msg}" != "" ]
then
read -p "${msg}" str
else
read -p "${msg}" str
fi
done
echo "${str}"
return 0
}
canonPath()
{
local cwd
local nwd
local nfn
cwd=`pwd -P`
nwd=`dirname "$1"`
nfn=`basename "$1"`
cd "${nwd}" >/dev/null 2>&1
if [ $? -ne 0 ]
then
cd "${cwd}"
return 1
fi
nwd=`pwd -P`
if [ -d "${nfn}" ]
then
cd "${nfn}" >/dev/null 2>&1
if [ $? -ne 0 ]
then
cd "${cwd}"
return 1
fi
nwd=`pwd -P`
echo "${nwd}"
else
echo "${nwd}/${nfn}"
fi
cd "${cwd}"
return 0
}
parseArgs()
{
local -i foundDSN=1
while [ $# -gt 0 ]
do
case "$1" in
"-dsn" )
shift
if [ \( ${foundDSN} -eq 0 \) -o \( $# -lt 1 \) ]
then
usage
fi
dsn="$1"
foundDSN=0
;;
* )
usage
;;
esac
shift
done
connstr="DSN=${dsn}"
return 0
}
createUser()
{
echo
echo "Creating user..."
echo
ttIsql "${connstr}" <<EOF
create user ${username} identified by '${password}';
grant create session to ${username};
grant create table, create view, create materialized view, create sequence, create procedure, create cache group, create synonym to ${username};
quit;
EOF
if [ $? -ne 0 ]
then
return 1
fi
return 0
}
parseArgs "$@"
warnUser
dir=`canonPath "$0"`
dir=`dirname "${dir}"`
cd "${dir}"
username=`getString "Enter the name of the user to create: "`
password=`getString "Enter the password to be assigned to '${username}': "`
createUser
exit $?