Guest User

deluge free space monitor

a guest
Jan 21st, 2018
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.25 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Adjust these parameters to your system
  4. fileSystem="/data"     # Filesystem you want to monitor
  5. minFreeSpacePct="10"   # Free space threshold percentage
  6. checkInterval="10"     # Interval between checks in seconds
  7.  
  8. while (:); do
  9.     # Get the output of df -k and put in a variable for parsing
  10.     dfOutPut=$(df -k ${fileSystem}|tail -n1)
  11.  
  12.     # Exctract the fields containing total and available 1K-blocks
  13.     totalBlocksKb=$(echo ${dfOutPut} | awk '{print $2}')
  14.     availableBlocksKb=$(echo ${dfOutPut} | awk '{print $4}')
  15.  
  16.     # Calculate percentage of free space
  17.     let freeSpacePct=100\*${availableBlocksKb}/${totalBlocksKb}
  18.  
  19.     # Check if free space percentage is below threshold value
  20.     if [ "${freeSpacePct}" -lt "${minFreeSpacePct}" ]; then
  21.         date +'%Y-%m-%d %H:%M:%S'
  22.         echo "You only have ${freeSpacePct}% free space on ${fileSystem}"
  23.         echo "This is below threshold value ${minFreeSpacePct}%"
  24.         echo "Killing deluge"
  25.         pkill deluge
  26.         exit 1
  27.     else
  28.         date +'%Y-%m-%d %H:%M:%S'
  29.         echo "You still have ${freeSpacePct}% free space on ${fileSystem}"
  30.         echo "Threshold value is ${minFreeSpacePct}%"
  31.         echo "All is well"
  32.         sleep ${checkInterval}
  33.     fi
  34. done
Add Comment
Please, Sign In to add comment