#/bin/bash
free_percent=$(df -h | grep /data | awk '{print $5}')
free_percent_no=$(df -h | grep /data | awk '{print $5}' | sed 's/%//')
free_no=$(df -h | grep /data | awk '{print $4}')
FILE=/root/cron_diskspace_notification
if [ "$free_percent_no" -gt "95" ]; then
if [[ ! -f "$FILE" ]]; then
curl -X POST https://chat.example.com.hr/api/v1/messages \
-u name-bot@chat.example.com.hr:<key> \
-d "type=stream" \
-d "to=Infrastructure" \
-d "subject=Disk space" \
-d $"content=Disk usage is abowe 95%. Currently at $free_percent. Free space is: $free_no"
touch $FILE
datum=$( date +%F )
echo "$datum" > $FILE
else
datum=$( date +%F )
datumf=`cat $FILE`
if [ "$datum" != "$datumf" ]; then
echo "$datum" > $FILE
curl -X POST https://chat.example.com.hr/api/v1/messages \
-u name-bot@chat.example.com.hr:<key> \
-d "type=stream" \
-d "to=Infrastructure" \
-d "subject=Disk space" \
-d $"content=Disk usage is abowe 95%. Currently at $free_percent. Free space is: $free_no"
fi
fi
else
if [[ -f "$FILE" ]]; then
rm $FILE
fi
fi