Last active
August 9, 2019 11:51
-
-
Save DeviousPenguin/8c965557a67d982f44eb3974c37fc830 to your computer and use it in GitHub Desktop.
# Log Monitor - Used to monitor the size of a logfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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