improve incs policy parsing

This commit is contained in:
Jérémy Lecour 2020-04-02 23:52:27 +02:00 committed by Jérémy Lecour
parent 492433133e
commit c920e91304
3 changed files with 13 additions and 10 deletions

View file

@ -83,7 +83,7 @@ for jail_name in $(jails_list); do
trap "rm ${incs_policy_keep_file}" 0
# loop for each line in jail configuration
for incs_policy_line in $(cat ${incs_policy_file} | grep "^\+"); do
for incs_policy_line in $(grep "^\+" ${incs_policy_file}); do
# inc date in ISO format
incs_policy_date=$(relative_date ${incs_policy_line})
echo ${incs_policy_date} >> "${incs_policy_keep_file}"

View file

@ -34,13 +34,15 @@ trap "rm ${duc_output} ${incs_output} ${stat_output}" 0
awk '{ print $2 }' "${duc_output}" | 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}"
inc=0
if [ -f "${CONFDIR}/${jail_name}" ]; then
day=$(grep -c "day" "${CONFDIR}/${jail_name}")
month=$(grep -c "month" "${CONFDIR}/${jail_name}")
inc="${day}/${month}"
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 "${inc}" >> "${incs_output}"
echo "${incs_policy}" >> "${incs_output}"
done
paste "${duc_output}" "${incs_output}" "${stat_output}" | awk '{ printf("%- 30s %- 10s %- 10s %- 15s\n", $2, $1, $3, $4); }'

View file

@ -13,10 +13,11 @@ if [ ! -n "${jail_name}" ]; then
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 [ -f "${CONFDIR}/${jail_name}" ]; then
days=$(grep -c "day" "${CONFDIR}/${jail_name}")
months=$(grep -c "month" "${CONFDIR}/${jail_name}")
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