Skip to content

Commit b8f5a11

Browse files
committed
Mysql password change
1 parent 527e4a9 commit b8f5a11

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
# info: change database server password
3+
# options: TYPE HOST USER PASSWORD
4+
#
5+
# The function changes database server password.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
type=$1
14+
host=$2
15+
dbuser=$3
16+
password=$4
17+
18+
# Includes
19+
source $VESTA/func/main.sh
20+
source $VESTA/func/db.sh
21+
source $VESTA/conf/vesta.conf
22+
23+
# Hiding password
24+
A4='******'
25+
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
26+
27+
28+
#----------------------------------------------------------#
29+
# Verifications #
30+
#----------------------------------------------------------#
31+
32+
args_usage='TYPE HOST DBUSER DBPASS'
33+
check_args '4' "$#" "$args_usage"
34+
validate_format 'host' 'dbuser'
35+
is_object_valid "../../conf/$type" 'HOST' "$host"
36+
dbpass="$password"
37+
38+
39+
#----------------------------------------------------------#
40+
# Action #
41+
#----------------------------------------------------------#
42+
43+
# Define email
44+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf |cut -f2 -d \')
45+
subj="v-change-database-host-password $*"
46+
47+
case $type in
48+
mysql) mysql_connect $host;
49+
query="USE mysql; UPDATE user SET"
50+
query="$query password=PASSWORD('$dbpass')"
51+
query="$query WHERE User='$dbuser';"
52+
query="$query FLUSH PRIVILEGES;"
53+
mysql_query "$query" ;;
54+
pgsql) echo "TBD" >/dev/null;;
55+
esac
56+
57+
update_object_value "../../conf/$type" 'HOST' "$host" '$USER' "$dbuser"
58+
update_object_value "../../conf/$type" 'HOST' "$host" '$PASSWORD' "$dbpass"
59+
60+
61+
#----------------------------------------------------------#
62+
# Vesta #
63+
#----------------------------------------------------------#
64+
65+
# Logging
66+
log_event "$OK" "$EVENT"
67+
68+
exit

0 commit comments

Comments
 (0)