Check Server Status and Create Notification on Apple Mac
- Categories:
- notes
Inspired by my previous script, I decide to create simple shell script to check and monitor my server and run it on my Mac.
The script uses ping
command to check my server, if exit status is not equal to zero, it means my server is down and it will create notification on my Mac.
#!/bin/bash
# How to use: ./check_server.sh example.com
domain=$1
echo "Checking ${domain}"
ping -c 3 -q $domain > /dev/null
exit_status=$?
if [ $exit_status -eq 0 ]; then
echo "${domain} is up"
fi
echo "Monitoring the status of ${domain} every 1 minute"
while true
do
# -c <number>: Stop after sending <number> packages
# -q: quiet output
ping -c 3 -q $domain > /dev/null
exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "${domain} is down"
osascript -e 'display notification "check_server.sh" with title "Status" subtitle "Server is down!" sound name "Hero"'
fi
# check every 1 minute
sleep 60
done
You can get my script above on Github.
Recent Posts
AWS Secrets Manager
Explanation about AWS Secrets Manager with example code.
Envelope Encryption
Envelope encryption is the practice of encrypting plaintext data with a data key, and then encrypting the data key under another key.
Tutorial - "su username vs su - username" - A Security Perspective
The main difference between `su username` and `su - username` lies in the environment variables that are loaded when switching to the specified user.
Subdomain Hijacking
My dormant subdomain was recently hijacked, redirecting it to a online gamble registration page.
C# DbContext ServiceLifeTime
my note about C Sharp ServiceLifeTime