Improve readability
parent
01295e851f
commit
0bffafcc82
|
@ -30,38 +30,8 @@ SERVICES=(
|
||||||
#mail.openworlds.info
|
#mail.openworlds.info
|
||||||
)
|
)
|
||||||
|
|
||||||
rotate_log()
|
main()
|
||||||
{
|
{
|
||||||
local -n log=$1
|
|
||||||
local max_log=4096 # 4M as we get size in K below
|
|
||||||
local log_size=$(du -k "${log}" | cut -f 1)
|
|
||||||
|
|
||||||
if ((${log_size} > ${max_log})); then
|
|
||||||
# Clobber any previous backup
|
|
||||||
mv -f ${log} ${log}.1
|
|
||||||
fi
|
|
||||||
|
|
||||||
touch ${log}
|
|
||||||
}
|
|
||||||
|
|
||||||
send_mail()
|
|
||||||
{
|
|
||||||
local -n error_list=$1
|
|
||||||
local error_string=""
|
|
||||||
|
|
||||||
for i in "${!error_list[@]}"; do
|
|
||||||
# Use bash's awful syntax to escape any / in the server string
|
|
||||||
code=${i//\//\\\/}
|
|
||||||
server=${error_list[$i]}
|
|
||||||
error_string+=" ${code}: ${server}\n"
|
|
||||||
done
|
|
||||||
|
|
||||||
cat mail_template \
|
|
||||||
| sed "s/{ERR_LIST}/${error_string}/g" \
|
|
||||||
| msmtp -a omn_server_watch ${RECIPIENTS[@]} \
|
|
||||||
|| echo "[ERROR] Failed to send mail!"
|
|
||||||
}
|
|
||||||
|
|
||||||
declare -A FLAGGED
|
declare -A FLAGGED
|
||||||
|
|
||||||
rotate_log LOG_FILE
|
rotate_log LOG_FILE
|
||||||
|
@ -88,7 +58,6 @@ ret=0
|
||||||
|
|
||||||
if ((${#FLAGGED[@]} > 0)); then
|
if ((${#FLAGGED[@]} > 0)); then
|
||||||
echo "== Error(s) detected. Sending mail to:"
|
echo "== Error(s) detected. Sending mail to:"
|
||||||
|
|
||||||
for rcp in ${RECIPIENTS[@]}; do
|
for rcp in ${RECIPIENTS[@]}; do
|
||||||
echo " ${rcp}"
|
echo " ${rcp}"
|
||||||
done
|
done
|
||||||
|
@ -101,3 +70,41 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit ${ret}
|
exit ${ret}
|
||||||
|
}
|
||||||
|
|
||||||
|
rotate_log()
|
||||||
|
{
|
||||||
|
local -n log=$1
|
||||||
|
local max_log=4096 # 4M as we get size in K below
|
||||||
|
|
||||||
|
touch ${log}
|
||||||
|
|
||||||
|
local log_size=$(du -k "${log}" | cut -f 1)
|
||||||
|
|
||||||
|
if ((${log_size} > ${max_log})); then
|
||||||
|
# Clobber any previous backup
|
||||||
|
mv -f ${log} ${log}.1
|
||||||
|
touch ${log}
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
send_mail()
|
||||||
|
{
|
||||||
|
local -n error_list=$1
|
||||||
|
local error_string=""
|
||||||
|
|
||||||
|
for i in "${!error_list[@]}"; do
|
||||||
|
# Use bash's awful syntax to escape any / in the server string
|
||||||
|
code=${i//\//\\\/}
|
||||||
|
server=${error_list[$i]}
|
||||||
|
error_string+=" ${code}: ${server}\n"
|
||||||
|
done
|
||||||
|
|
||||||
|
cat mail_template \
|
||||||
|
| sed "s/{ERR_LIST}/${error_string}/g" \
|
||||||
|
| msmtp -a omn_server_watch ${RECIPIENTS[@]} \
|
||||||
|
|| echo "[ERROR] Failed to send mail!"
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
||||||
|
|
Loading…
Reference in New Issue