Getting Guestbook Notifications on EMail

| ~1 minute read


I use this server to power the guestbook on my website, but it gets annoying to ssh into my server and see if there are any updates, and there mostly aren't any.

So, I built a script and added it as a cronjob so I get updates if there are any new entries, once every morning, and once every night.

#!/usr/bin/env bash

entries=$(/root/go/bin/guestbook dump)

if [ -z "$(echo "$entries" | tr -d '[:space:]')" ]; then
	echo "[$(date)] guestbook_notify: no new entries."
else
	# replace vidhukant with your username/email address
	mail -s "Daily Guestbook Update" vidhukant <<< "$entries"
fi

Then, I added this to crontab.

crontab -e

This opens your user's crontab. Now add this line:

30 8,20 * * * /root/guestbook_notify.sh

With this, if there are any entries, I get notified at 8:30 a.m. and 8:30 p.m. everyday!

I just hope this doesn't introduce some sort of vulnerability... (beware if you try this, it's not my responsibility)