Skip to content

Instantly share code, notes, and snippets.

@colindaven
Forked from brimur/checkDisk.sh
Last active October 25, 2021 10:11
Show Gist options
  • Save colindaven/3fdc159919abd7f6becc446a0c472342 to your computer and use it in GitHub Desktop.
Save colindaven/3fdc159919abd7f6becc446a0c472342 to your computer and use it in GitHub Desktop.
Cron script to control
# Name: checkDisk.sh
# Created by: Originally by Brimur, simple rewrite for sftp by colindaven
# Created: Nov 26th 2019, Oct 2021
# This script is used to control sftp jobs based on available disk space.
#
# This should be run as a cronjob (every minute) on the server/computer running sftp
#
# If you use a download manager tell it to add jobs as PAUSED
#
# - If disk is nearly full (limit) then stop all sftp jobs - kill
#
############################
#!/bin/bash
echo "DO NOT USE ! UNDER CONSTRUCTION !!! "
# Customise here...
#partition="/dev/mapper/vg-lv_root"
partition=" / "
threshold="90"
#End customise
# TODO: test this egrep with root partition!!
percent=$(df -h | egrep $partition | awk '{ print $5 }' | sed 's/%//g')
echo Disk is "$percent" % full
if ((percent > threshold))
then
echo "Disk is "$percent" % full. Stopping sftp via killall."
killall sftp
else
space=$(df -h | grep "$partition" | awk '{ print $4 }' | sed 's/G//g')
space=$(echo "($space*1000 +0.5)/1" | bc)
# write this to logfile via ansible cron job, but refresh if too big
echo 'Free space is "$space" MBs'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment