Last active
October 9, 2019 21:48
-
-
Save LiamKarlMitchell/a567536d6914df788ef95c249a1edc8e to your computer and use it in GitHub Desktop.
Linux utility scripts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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="[email protected]" | |
to="[email protected]" | |
# 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" "[email protected]" | |
fi | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SENDGRID_API_KEY="SG.YOUR_SENDGRID_API_KEY_HERE" | |
EMAIL_TO="[email protected]" | |
FROM_EMAIL="[email protected]" | |
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": "[email protected]"}],"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