#!/bin/bash # # vhost-stack # https://git.stack-source.com/msb/vhost-stack # Copyright (c) 2023 Matthew Saunders Brown # 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 ] [-c] [-h]" echo "" echo " -h Print this help." echo " -d 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 (unknown) (unknown) (unknown) (unknown)" fi done if [[ $cvs ]]; then echo "$output" | tr " " "," else echo "$output" | column -t fi