vmail-stack/bin/vmail-domains-get.sh
Matthew Saunders Brown 05996c8c4d return specific fields
2022-05-10 10:32:57 -07:00

49 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
#
# vmail-stack
# https://git.stack-source.com/msb/vmail-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown
# load include file
source $(dirname $0)/vmail.sh
help()
{
thisfilename=$(basename -- "$0")
echo "$thisfilename"
echo "Get domain data from vmail database."
echo ""
echo "usage: $thisfilename [-d <domain>|-g <glob>] [OPTIONS]"
echo ""
echo " -h Print this help."
echo " -d Domain to be queried."
echo " -g Glob - Wildcard search instead of specific domain search."
echo " -c Output in cvs format."
echo " -t Use tabs instead of tables for output, do not display column headers."
echo ""
echo " Domain/Glob is optional. If nothing specified all domains will be queried."
echo " Domain search is for an exact match."
echo " Use -g instead of -d for glog (wildcard) search. e.g:"
echo " $thisfilename -g stack # search for all domains that contain 'stack'."
exit
}
vmail:getoptions "$@"
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE"
dbcmdopts="-e"
if [[ -n $tab ]]; then
dbcmdopts="-s -N $dbcmdopts"
fi
dbquery="SELECT domain, status, mbox_limit, mbox_quota_default, mbox_ratelimit_default FROM vm_domains"
# build query
if [[ -n $domain ]]; then
dbquery="$dbquery WHERE domain='$domain'"
elif [[ -n $glob ]]; then
dbquery="$dbquery WHERE domain LIKE '%$domain%'"
fi
# execute mysql query
eval $dbcmd $dbcmdopts "\"$dbquery;\"" $cvs