Comment on How to get a phone notification if my VPS goes offline?

realitaetsverlust@piefed.zip ⁨2⁩ ⁨days⁩ ago

There’s a lot of options. There’s countless paid services that offer exactly that.

If you wanna build something yourself for free, you could probably set up a site accessible via HTTP on your server and create a script on your phone that pings it every 30 seconds or so. Afaik, termux has a termux-notify function that lets you send a notification.

Pseudocodelike, it would look somewhere like this I think:

#!/usr/bin/env bash

# Config 
NOTIFY_TITLE="Server Alert"
NOTIFY_MESSAGE="Server returned a non‑200 status."

HOST="funnysite.com"
PORT=8080
PATH="/healtcheck"

URL="http://${HOST}:${PORT}${PATH}"
# Config

HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$URL")

if [[ "$HTTP_CODE" != "200" ]]; then
    termux-notify -t "$NOTIFY_TITLE" -c "$NOTIFY_MESSAGE $HOST:$PORT → $HTTP_CODE"
fi

exit 0

Afaik, termux doesn’t ship the cron daemon, but you can install cronie or use an external task scheduler. There, just set to run the script every 60 seconds or so. Whatever you need.

I haven’t tested anything of this, but in my head, it sounds like it should work fine.

source
Sort:hotnewtop