linux:misc:cron:diskspace_zulip_notify

no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


linux:misc:cron:diskspace_zulip_notify [2020/06/01 10:35] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== Send Zulip notification on low disk space in Linux ======
 +<code bash>
 +#/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
 +</code>
  • linux/misc/cron/diskspace_zulip_notify.txt
  • Last modified: 2020/06/01 10:35
  • by 127.0.0.1