vmail-stack/bin/vmail-domains-get.sh

49 lines
1.5 KiB
Bash
Raw Normal View History

2021-02-10 16:16:23 -08:00
#!/bin/bash
#
# vmail-stack
# https://git.stack-source.com/msb/vmail-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown
2021-04-02 12:02:50 -07:00
# load include file
source $(dirname $0)/vmail.sh
2021-02-10 16:16:23 -08:00
help()
{
thisfilename=$(basename -- "$0")
echo "$thisfilename"
echo "Get domain data from vmail database."
echo ""
2021-10-15 15:17:29 -07:00
echo "usage: $thisfilename [-d <domain>|-g <glob>] [OPTIONS]"
2021-02-10 16:16:23 -08:00
echo ""
echo " -h Print this help."
2021-10-15 15:17:29 -07:00
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."
2021-02-10 16:16:23 -08:00
echo ""
2021-10-15 15:17:29 -07:00
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'."
2021-02-10 16:16:23 -08:00
exit
}
2021-10-15 15:17:29 -07:00
vmail:getoptions "$@"
2021-02-10 16:16:23 -08:00
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE"
dbcmdopts="-e"
2021-10-15 15:17:29 -07:00
if [[ -n $tab ]]; then
dbcmdopts="-s -N $dbcmdopts"
2021-02-10 16:16:23 -08:00
fi
2022-05-10 10:32:57 -07:00
dbquery="SELECT domain, status, mbox_limit, mbox_quota_default, mbox_ratelimit_default FROM vm_domains"
2021-02-10 16:16:23 -08:00
# build query
2021-10-15 15:17:29 -07:00
if [[ -n $domain ]]; then
dbquery="$dbquery WHERE domain='$domain'"
elif [[ -n $glob ]]; then
dbquery="$dbquery WHERE domain LIKE '%$domain%'"
2021-02-10 16:16:23 -08:00
fi
# execute mysql query
eval $dbcmd $dbcmdopts "\"$dbquery;\"" $cvs