Created
September 4, 2021 04:27
-
-
Save wannadrunk/05b011cc1a80d6b5559e7c3b0532f27a to your computer and use it in GitHub Desktop.
Bash script to check the diskspace and send the notification to LINE.
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
#!/bin/bash | |
### Author: cHoo | |
### Date: September 2019 | |
### Version: 1.0 | |
### Description: Check diskspace used and alert if used up to 90% | |
# | |
# Import global variable | |
# | |
CONFLE="/opt/scripts/setting.ini" | |
if [ -f $CONFLE ] | |
then | |
source $CONFLE | |
LINEMSG=".\n$HOSTNAME - $0" | |
else | |
LOGTIME=`date '+%Y-%m-%d_%H:%M:%S'` | |
LINETOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
LINEMSG="$0 - $LOGTIME - Config not found." | |
curl -X POST -H "Authorization: Bearer $LINETOKEN" -F "message=$LINEMSG" https://notify-api.line.me/api/notify | |
echo -e "\n" | |
exit | |
fi | |
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output; | |
do | |
echo $output | |
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 ) | |
partition=$(echo $output | awk '{ print $2 }' ) | |
if [ $usep -ge 95 ]; then | |
curl -X POST -H "Authorization: Bearer $LINETOKEN" -F "message=Disk $partition on $HOSTNAME use $usep % nearly FULL." -F "stickerPackageId=1" -F "stickerId=123" https://notify-api.line.me/api/notify | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
setting.ini consist of variables
LINETOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"