Last active
July 12, 2022 08:55
-
-
Save cpecorari/1d1643b01f108406514b6f730a4043b3 to your computer and use it in GitHub Desktop.
Server Disk Space Check & mail notification
This file contains 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/sh | |
apt update && \ | |
apt install postfix mailutils && \ | |
# manually cofigure postfix with "Internet site" | |
echo "test" | mail your@email.com |
This file contains 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
# size limit you want to alert at | |
ALERT=200 | |
UNIT=G | |
# Choose partition to check | |
PARTITION=/dev/nvme1n1 | |
df -B$UNIT | grep "^$PARTITION" | | |
while read partition size used free perc mnt ; | |
do | |
free_space=$(echo $free | tr -d $UNIT ) | |
if [ $free_space -le $ALERT ]; then | |
echo "Partition $partition ($mnt) running out of space ($free) on $(hostname) as on $(date)" | mail -s "Alert: $mnt almost out of disk space on $(hostname) - $free" your@email.com,other@email.com | |
fi | |
done |
This file contains 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
IP=192.168.1.3 | |
PORT=8545 | |
curl "$IP:$PORT" \ | |
-X POST \ | |
-H "Content-Type: application/json" \ | |
--data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":67}' | |
retval=$? | |
if [ $retval -eq 0 ]; then | |
echo OK | |
else | |
echo "Node at address $IP (port $PORT) is not responding anymore on $(hostname) as of $(date)" | mail -s "Alert: node on $(hostname) / $IP stopped" your@email.com,other@email.com | |
fi |
This file contains 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
# /etc/crontab: system-wide crontab | |
# Unlike any other crontab you don't have to run the `crontab' | |
# command to install the new version when you edit this file | |
# and files in /etc/cron.d. These files also have username fields, | |
# that none of the other crontabs do. | |
SHELL=/bin/sh | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
# Example of job definition: | |
# .---------------- minute (0 - 59) | |
# | .------------- hour (0 - 23) | |
# | | .---------- day of month (1 - 31) | |
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ... | |
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat | |
# | | | | | | |
# * * * * * user-name command to be executed | |
17 * * * * root cd / && run-parts --report /etc/cron.hourly | |
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) | |
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) | |
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) | |
0 * * * * root bash /home/user/disk-space.sh |
This file contains 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 | |
CONTAINER_NAME=mycontainer | |
RESPONSE=$(docker ps -a | grep $CONTAINER_NAME) | |
if [ -n "$(echo $RESPONSE | grep -i 'exited')" ] | |
then | |
echo "$(date) Container $CONTAINER_NAME has exited, restarting..." | |
docker restart $CONTAINER_NAME ; | |
else | |
echo "$CONTAINER_NAME running..." | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment