new script vhost-mysql-db-get.sh
This commit is contained in:
parent
7afc8ad284
commit
057afa6e12
65
bin/vhost-mysql-db-get.sh
Executable file
65
bin/vhost-mysql-db-get.sh
Executable file
|
@ -0,0 +1,65 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# vhost-stack
|
||||||
|
# https://git.stack-source.com/msb/vhost-stack
|
||||||
|
# Copyright (c) 2023 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
# load include file
|
||||||
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Get MySQL database connection information."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename [-d <domain>] [-c] [-h]"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
echo " -d <domain> Get MySQL DB info for specified domain, otherwise return DB info for all domains."
|
||||||
|
echo " -c CVS - Output in cvs format, instead of tabbed table."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
vhost:getoptions "$@"
|
||||||
|
|
||||||
|
# create newline var
|
||||||
|
NL=$'\n'
|
||||||
|
|
||||||
|
if [[ -n $domain ]]; then
|
||||||
|
if [[ -d /srv/www/$domain ]]; then
|
||||||
|
virtualhostArray=($domain)
|
||||||
|
else
|
||||||
|
echo "ERROR: $domain not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
vhost::set-virtualhostArray
|
||||||
|
fi
|
||||||
|
|
||||||
|
output="virtualhost hostname database username password"
|
||||||
|
|
||||||
|
for v in "${virtualhostArray[@]}"
|
||||||
|
do
|
||||||
|
if [[ -f /srv/www/$v/.my.cnf ]]; then
|
||||||
|
|
||||||
|
hostname=`grep ^host= /srv/www/$v/.my.cnf |cut -d = -f 2`
|
||||||
|
database=`grep ^database= /srv/www/$v/.my.cnf |cut -d = -f 2`
|
||||||
|
username=`grep ^user= /srv/www/$v/.my.cnf |cut -d = -f 2`
|
||||||
|
password=`grep ^password= /srv/www/$v/.my.cnf |cut -d = -f 2`
|
||||||
|
|
||||||
|
output="$output${NL}$v $hostname $database $username $password"
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
output="$output${NL}$v"
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ $cvs ]]; then
|
||||||
|
echo "$output" | tr " " ","
|
||||||
|
else
|
||||||
|
echo "$output" | column -t
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user