Created
February 25, 2019 15:41
-
-
Save 1gg/e8cca2da4164a91527c6e867c6e5b3f9 to your computer and use it in GitHub Desktop.
check_folder_size_cpu.sh
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
#!/bin/bash | |
sizingFolder="/home/user" | |
watchFolder="/home/user/deluge/watch" | |
currentFolderSize=$(du -s "$sizingFolder" | awk '{ print $1}') | |
sizeThreshold=545706008 | |
currentCPUUsage=$(top -b -n 1 -p $(pgrep -d',' deluged) | grep deluged | awk '{ print $9}') | |
currentCPUUsage=${currentCPUUsage%%.*} | |
CPUThreshold=100 | |
torrentLink=$1 | |
torrentName=$2 | |
if [ "$currentFolderSize" -lt "$sizeThreshold" ] && [ "$currentCPUUsage" -lt "$CPUThreshold" ] | |
then | |
echo $(date +"%Y-%m-%d_%H:%M:%S.%3N")" ------Current Folder Size="$currentFolderSize" KB and CPU Usage="$currentCPUUsage"%. Adding torrent: "$torrentName >> $sizingFolder/log_checkSize_dl.txt | |
wget -O $watchFolder"/dl.torrent" $torrentLink >> $sizingFolder/log_checkSize_dl.txt | |
elif [ "$currentFolderSize" -lt "$sizeThreshold" ] | |
then | |
echo $(date +"%Y-%m-%d_%H:%M:%S.%3N")" ------Alert: CPU usage "$currentCPUUsage"% is higher than CPUThreshold= "$CPUThreshold"%. Skipping torrent: "$torrentName >> $sizingFolder/log_checkSize_dl.txt | |
else | |
echo $(date +"%Y-%m-%d_%H:%M:%S.%3N")" ------Alert: Folder Size "$currentFolderSize" KB is higher than sizeThreshold= "$sizeThreshold" KB. Skipping torrent: "$torrentName >> $sizingFolder/log_checkSize_dl.txt | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment