#!/bin/sh # # Description: Display stats on jails (size, last connection…) # Usage: stats # # shellcheck source=./includes LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes" mkdir -p "${INDEX_DIR}" lsof "${IDX_FILE}" >/dev/null 2>&1 || nohup sh -s -- </dev/null 2>&1 & ionice -c3 "${DUC}" index -d "${IDX_FILE}" "${JAILDIR}" touch "${INDEX_DIR}/.lastrun.duc" EOF [ ! -f "${INDEX_DIR}/.lastrun.duc" ] && notice "First run of DUC still in progress ..." && exit 0 [ ! -f ${IDX_FILE} ] && error "Index file doesn't exits !" printf "Last update of index file : " stat --format=%Y "${INDEX_DIR}/.lastrun.duc" | xargs -i -n1 date -R -d "@{}" duc_output=$(mktemp) stat_output=$(mktemp) incs_output=$(mktemp) jail_patterns_list=$(mktemp) # shellcheck disable=SC2064 trap "rm ${duc_output} ${incs_output} ${stat_output} ${jail_patterns_list}" 0 "${DUC}" ls --database "${IDX_FILE}" "${JAILDIR}" > "${duc_output}" jails_list | sed -e "s/^\(.*\)$/\\\\b\1\\\\b/" > "${jail_patterns_list}" grep -f "${jail_patterns_list}" "${duc_output}" | awk '{ print $2 }' | while read jail_name; do jail_path=$(jail_path "${jail_name}") stat --format=%Y "${jail_path}/var/log/lastlog" | xargs -i -n1 date -d "@{}" "+%d-%m-%Y" >> "${stat_output}" 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 echo "${incs_policy}" >> "${incs_output}" done ( echo " " paste "${duc_output}" "${incs_output}" "${stat_output}" | awk '{ printf("%s %s %s %s\n", $2, $1, $3, $4); }' ) | column -t