Skip to content

Instantly share code, notes, and snippets.

@LiamKarlMitchell
Last active October 9, 2019 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LiamKarlMitchell/a567536d6914df788ef95c249a1edc8e to your computer and use it in GitHub Desktop.
Save LiamKarlMitchell/a567536d6914df788ef95c249a1edc8e to your computer and use it in GitHub Desktop.
Linux utility scripts.
#!/bin/bash
#######################################################################################
# Script Name : alertstorage.sh
# Description : Send alert mail when server storage is running low.
# Args :
# Author : Liam Mitchell
# License : MIT
#######################################################################################
subject="Server Storage Alert - ServerName"
from="cron@somesite.co.nz"
to="myemail@work.co.nz"
# Get total storage %.
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=90
# Check if storage is greater than the threshold precentage.
if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
# Send email if system storage is running low.
echo -e "Warning, server storage is running low!" | mailx -s "$subject" -r "$from" "$to" "anotheremail@work.co.nz"
fi
exit 0
#!/bin/bash
SENDGRID_API_KEY="SG.YOUR_SENDGRID_API_KEY_HERE"
EMAIL_TO="someemail@work.co.nz"
FROM_EMAIL="SomeServer@work.co.nz"
FROM_NAME="SomeServer"
SUBJECT="Low Disk Space Email"
bodyHTML="<p>Testing sending email using sendgrid from sh.</p>"
maildata='{"personalizations": [{"to": [{"email": "'${EMAIL_TO}'"}]}],"cc":[{"email": "someccemail@work.co.nz"}],"from": {"email": "'${FROM_EMAIL}'",
"name": "'${FROM_NAME}'"},"subject": "'${SUBJECT}'","content": [{"type": "text/html", "value": "'${bodyHTML}'"}]}'
curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header 'Authorization: Bearer '$SENDGRID_API_KEY \
--header 'Content-Type: application/json' \
--data "'$maildata'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment