Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Adjust these parameters to your system
- fileSystem="/data" # Filesystem you want to monitor
- minFreeSpacePct="10" # Free space threshold percentage
- checkInterval="10" # Interval between checks in seconds
- while (:); do
- # Get the output of df -k and put in a variable for parsing
- dfOutPut=$(df -k ${fileSystem}|tail -n1)
- # Exctract the fields containing total and available 1K-blocks
- totalBlocksKb=$(echo ${dfOutPut} | awk '{print $2}')
- availableBlocksKb=$(echo ${dfOutPut} | awk '{print $4}')
- # Calculate percentage of free space
- let freeSpacePct=100\*${availableBlocksKb}/${totalBlocksKb}
- # Check if free space percentage is below threshold value
- if [ "${freeSpacePct}" -lt "${minFreeSpacePct}" ]; then
- date +'%Y-%m-%d %H:%M:%S'
- echo "You only have ${freeSpacePct}% free space on ${fileSystem}"
- echo "This is below threshold value ${minFreeSpacePct}%"
- echo "Killing deluge"
- pkill deluge
- exit 1
- else
- date +'%Y-%m-%d %H:%M:%S'
- echo "You still have ${freeSpacePct}% free space on ${fileSystem}"
- echo "Threshold value is ${minFreeSpacePct}%"
- echo "All is well"
- sleep ${checkInterval}
- fi
- done
Add Comment
Please, Sign In to add comment