linux:misc:cron:diskspace_zulip_notify

Send Zulip notification on low disk space in Linux

#/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
Enter your comment:
77 -6 = 
 
  • linux/misc/cron/diskspace_zulip_notify.txt
  • Last modified: 2020/06/01 10:35
  • by 127.0.0.1