#!/bin/sh
# The script monitors the log files. If they reach a limit, truncate them
WTMP_FILE=/var/log/wtmp
SLPD_FILE=/var/log/slpd_xmalloc.log

get_wtmp_size() {
    set -- $( ls -s /var/log/wtmp )
    wtmp_size=$1
}

get_slpd_size() {
	set -- $( ls -s /var/log/slpd_xmalloc.log )
	slpd_size=$1
}

# Truncate the wtmp file if it is greater than 4KB
if [ -e ${WTMP_FILE} ]
then
	get_wtmp_size
	printf "wtmp size %d\n" ${wtmp_size}
	if [ ${wtmp_size} -gt 4 ]
	then
    	> /var/log/wtmp
    	/fabos/rbin/sync
    	get_wtmp_size
    	printf "tidy wtmp size %d\n" ${wtmp_size}
	fi
fi

# Truncate the SLPD file if it is greater than 4KB
if [ -e ${SLPD_FILE} ]
then
	get_slpd_size
	printf "slpd size %d\n" ${slpd_size}
	if [ ${slpd_size} -gt 4 ]
	then
    > /var/log/slpd_xmalloc.log
	/fabos/rbin/sync
    get_slpd_size
	printf "tidy slpd size %d\n" ${slpd_size}
	fi
fi

