Daily server status notifications with Ntfy

A quick tip on how to send a daily notification through Ntfy with three basic server statistics: memory usage, disk usage, and CPU load.

  1. If you have no intention to use the default Ntfy instance and wish to set up your own, please refer to installation instructions.

  2. Create a server-status bash file in your chosen location and open it for editing:

nano /scripts/bash/server-status
  1. Paste following into the file:
#/usr/bin/bash

MEMORY_USAGE=`free -m | awk 'NR==2{printf "Memory Usage: %s/%s MB (%.0f%%)", $3,$2,$3*100/$2 }'` 

DISK_USAGE=`df -h | awk '$NF=="/"{printf "Disk Usage: %.1f/%.1f GB (%s)", $3,$2,$5}'` 

CPU_LOAD=`top -bn1 | grep load | awk '{printf "CPU Load: %.2f%%", $(NF-2)}'` 

curl \
-H "Authorization: Basic abCdeFghiJK1" \
-H "Title: Server status report" \
-H "Tags: computer" \
-d "$MEMORY_USAGE
$DISK_USAGE
$CPU_LOAD" \
https://ntfy.example.com/vps

While replacing below values:

  • https://ntfy.example.com/vps with url to the appropriate topic on your Ntfy instance,
  • abCdeFghiJK1 in curl’s Authorization header with your own encoded user+password; if the instance does not require authorization, delete the whole -H "Authorization: Basic abCdeFghiJK1" \ line.
  1. Save the bash file with Ctrl+O.

  2. Exit the bash file with Ctrl+X.

  3. Make sure that the bash file is set as executable:

ls -la /scripts/bash/server-status
  1. Open crontab settings in edit mode:
crontab -e
  1. Add following line to crontab settings:
@daily /scripts/bash/server-status

If you’d like a more precise control over the time when the notification is send, please refer to crontab guru.

  1. Save the crontab settings with Ctrl+O.

  2. Exit the crontab settings file with Ctrl+X.