| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- #!/bin/bash
- # info: list database
- # options: user database [format]
- #
- # The function for obtaining of all database's parameters.
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument defenition
- user=$1
- database=$2
- format=${3-shell}
- # Importing variables
- source $VESTA/conf/vars.conf
- source $V_FUNC/shared.func
- source $V_FUNC/db.func
- # Json function
- json_list_db() {
- i=1
- # Define words number
- last_word=$(echo "$fields" | wc -w)
- # Reading file line by line
- line=$(grep "DB='$database'" $conf)
- # Print top bracket
- echo '{'
- # Parsing key=value
- eval $line
- # Starting output loop
- for field in $fields; do
- # Parsing key=value
- eval value=$field
- # Checking first field
- if [ "$i" -eq 1 ]; then
- echo -e "\t\"$value\": {"
- else
- if [ "$last_word" -eq "$i" ]; then
- echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
- else
- echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
- fi
- fi
- # Updating iterator
- (( ++i))
- done
- # If there was any output
- if [ -n "$value" ]; then
- echo -e "\t}"
- fi
- # Printing bottom json bracket
- echo -e '}'
- }
- # Shell list for single database
- shell_list_db() {
- # Reading file line by line
- line=$(grep "DB='$database'" $conf)
- # Parsing key=value
- eval $line
- # Print result line
- for field in $fields; do
- eval key="$field"
- echo "${field//$/}: $key "
- done
- }
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- # Checking args
- check_args '2' "$#" 'user db_name [format]'
- # Checking argument format
- format_validation 'user' 'database'
- # Checking user
- is_user_valid
- # Checking database exist
- is_db_valid
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Defining config
- conf=$V_USERS/$user/db.conf
- # Defining fileds to select
- fields='$DB $USER $HOST $TYPE $CHARSET $U_DISK $SUSPEND $DATE'
- # Listing database
- case $format in
- json) json_list_db ;;
- plain) shell_list_db ;;
- shell) shell_list_db | column -t ;;
- *) check_args '2' '0' 'user database [format]'
- esac
- #----------------------------------------------------------#
- # Vesta #
- #----------------------------------------------------------#
- exit
|