The Engagement 4Cast
In your server go to the /etc/cron.daily/ directory
Create a file named “diskstatus” (do not put any extension)
#!/bin/bash
# Parse df selected output
df -h|egrep -v 'File|tmpfs|docker|udev|loop'|
while read LINE; do
USED_NUMBER=`echo $LINE |awk '{print $5}'|sed 's/%//'|sed 's/ //g'`
USED_PERCENT=`echo $LINE |awk '{print $5}'|sed 's/ //g'`
MOUNT_POINT=`echo $LINE |awk '{print $6}'|sed 's/ //g'`
if [ $USED_NUMBER -gt 90 ]; then
# Create message without spaces
MESSAGE=`echo WARNING On $HOSTNAME disk $MOUNT_POINT is full at $USED_PERCENT usage WARNING|sed 's/ /_/g'`
# Post message
curl -X POST --data-urlencode
'payload={"channel": "#YOUR CHANNEL NAME", "username": "webhookbot", "text": "'$MESSAGE'", "icon_emoji": ":ghost:"}'
YOUR SLACK URL GOES HERE
fi
done
– Modify the code as needed
– Make sure that the file is executable (you may need to change the permissions)
– To check if the cron job has been added use the command “run-parts –test /etc/cron.daily” it should be listed along with the other cron jobs
-Alternatively, you can place a diskspace.sh file in the /usr/local/bin directory and create a crontab in the /etc directory to have the notification run whenever you want
Subscribe & stay ahead of the crowd with sage marketing tips and predictions.