evobackup/server/lib/bkctld-status

31 lines
1015 B
Bash
Executable File

#!/bin/sh
#
# Description: Display status of SSH server
# Usage: [--no-header] status [<jailname>|all]
#
# shellcheck source=./includes
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
jail_name="${1:?}"
if [ ! -n "${jail_name}" ]; then
show_help && exit 1
fi
[ -d "${JAILDIR}/${jail_name}" ] || error "${jail_name} : jail is missing.\nUse '$0 status [all]' to get the status of all jails."
incs_policy_file=$(current_jail_incs_policy_file ${jail_name})
incs_policy="0"
if [ -r "${incs_policy_file}" ]; then
days=$(grep "^\+" "${incs_policy_file}" | grep --count "day")
months=$(grep "^\+" "${incs_policy_file}" | grep --count "month")
incs_policy="${days}/${months}"
fi
status="OFF"
"${LIBDIR}/bkctld-is-on" "${jail_name}" && status="ON "
port=$("${LIBDIR}/bkctld-port" "${jail_name}")
ip=$("${LIBDIR}/bkctld-ip" "${jail_name}" | xargs | tr -s ' ' ',')
echo "${jail_name} ${status} ${port} ${incs_policy} ${ip}" | awk '{ printf("%- 30s %- 10s %- 10s %- 25s %- 20s\n", $1, $2, $3, $4, $5); }'