Files
VestaCP/bin/v_list_database_server

89 lines
2.2 KiB
Plaintext
Raw Normal View History

2011-06-14 00:22:25 +03:00
#!/bin/bash
2012-03-27 23:08:44 +03:00
# info: list database server
2012-01-03 21:47:10 +02:00
# options: type host [format]
2011-12-26 16:22:43 +02:00
#
2012-03-27 23:08:44 +03:00
# The function for obtaining database server parameters.
2011-12-26 16:22:43 +02:00
2011-06-14 00:22:25 +03:00
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
type=$1
host=$2
format=${3-shell}
2011-06-14 00:22:25 +03:00
2012-03-27 23:08:44 +03:00
# Includes
2012-04-30 12:32:11 +03:00
source $VESTA/func/main.sh
2011-06-14 00:22:25 +03:00
# Json function
json_list_dbhost() {
i=1
fields_count=$(echo "$fields" | wc -w)
line=$(grep "HOST='$host'" $conf)
echo '{'
2011-12-15 17:52:11 +02:00
eval $line
for field in $fields; do
eval value=$field
if [ "$i" -eq 1 ]; then
echo -e "\t\"$value\": {"
else
if [ "$fields_count" -eq "$i" ]; then
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
else
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
fi
fi
(( ++i))
done
if [ -n "$value" ]; then
echo -e "\t}"
fi
echo -e "}"
}
# Shell function
shell_list_dbhost() {
line=$(grep "HOST='$host'" $conf)
2011-12-15 17:52:11 +02:00
eval $line
for field in $fields; do
eval key="$field"
echo "${field//$/}: $key"
done
}
2011-06-14 00:22:25 +03:00
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'type host [format]'
2012-03-06 22:07:06 +02:00
validate_format 'host'
2012-03-27 23:08:44 +03:00
is_object_valid "../../conf/$type" 'HOST' "$host"
2011-06-14 00:22:25 +03:00
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining fileds to select
2012-03-27 23:08:44 +03:00
conf=$VESTA/conf/$type.conf
fields='$HOST $PORT $CHARSETS $MAX_DB $U_SYS_USERS $U_DB_BASES $TPL $SUSPENDED'
fields="$fields \$TIME \$DATE"
2011-06-14 00:22:25 +03:00
# Listing database
case $format in
json) json_list_dbhost ;;
plain) nohead=1; shell_list_dbhost ;;
shell) shell_list_dbhost | column -t;;
*) check_args '2' '0' 'type host [format]'
2011-06-14 00:22:25 +03:00
esac
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit