-
-
Save colindaven/3fdc159919abd7f6becc446a0c472342 to your computer and use it in GitHub Desktop.
Cron script to control
This file contains 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
# 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