#!/bin/sh

# The script monitors the disk usage for the root partition.

get_disk_usage() {
	set -- $( df / )
	# Skip the header "Filesystem 1k-blocks Used Available Use% Mounted on"
	shift 7
	# Remove the % sign from the Use% value
	disk_usage=${5%\%}
}

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

get_disk_usage

if [ ${disk_usage} -ge 80 ]
then
	get_wtmp_size

	# Truncate the wtmp file if it is greater than 1KB.
	if [ ${wtmp_size} -gt 1 ]
	then

		# Attempt to recover space by truncating the wtmp file.
		 > /var/log/wtmp

		/bin/sync

		get_wtmp_size

		# Add an entry in the error log.
		# To fix TR340854 Commenting the below line of code, not execute
		# in BFOS as "cf_msg" executable is not implemented for BFOS.

		# /sbin/cf_msg info "${disk_usage}" "${wtmp_size}"
	
	fi
fi

# Compress corefiles if they exist and Remove excessive core files

if [ -x /sbin/core_tidy.sh ] ; then
	set -e
	cd /core_files
	/sbin/core_tidy.sh -c
fi
