Skip to content

Instantly share code, notes, and snippets.

@DeviousPenguin
Last active August 9, 2019 11:51
Show Gist options
  • Select an option

  • Save DeviousPenguin/8c965557a67d982f44eb3974c37fc830 to your computer and use it in GitHub Desktop.

Select an option

Save DeviousPenguin/8c965557a67d982f44eb3974c37fc830 to your computer and use it in GitHub Desktop.
# Log Monitor - Used to monitor the size of a logfile
# Log Monitor - Used to monitor the size of a logfile
# Will truncate log file if it gets too large
# Start of script
# Set max size of logfile here, in bytes. Default = 1 Megabyte
MAXSIZE="1048576"
# Delete this file if you want script to stop running
RUNFILE="/tmp/log_monitor"
touch "$RUNFILE"
# Log file to monitor
LOGFILE="/var/log/pcp_squeezelite.log"
while [ -f "$RUNFILE" ]; do
# Get filesize in bytes
LOGSIZE=$(ls "$LOGFILE" -l | awk '{print $5}')
# Compare
if [ "$LOGSIZE" -gt "$MAXSIZE" ]; then
echo "Filesize $LOGSIZE is too large, truncating at $(date)" | tee "$LOGFILE"
else
echo "Filesize $LOGSIZE is OK"
fi
# Wait 1 min
sleep 60
done
exit 0
# End of script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment