-
Notifications
You must be signed in to change notification settings - Fork 0
/
isupaul.sh
35 lines (32 loc) · 1 KB
/
isupaul.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
# Is Up, Paul? by Ryan Kitty & ChatGPT. Will ping an IP address and then send an email if it doesn't reply.
# Replace 'your_server_ip' with the IP address you want to ping
ip_to_ping="your_server_ip"
# Function to send email
send_email() {
echo "The IP address $ip_to_ping is unreachable." | mail -s "The IP address is unreachable" [email protected]
}
# Check for command-line arguments
while getopts ":d" opt; do
case $opt in
d)
if ! ping -c 1 $ip_to_ping &> /dev/null; then
send_email
else
echo "The IP address $ip_to_ping is reachable."
fi
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# If no option provided, do regular ping check
if [ $OPTIND -eq 1 ]; then
if ! ping -c 1 $ip_to_ping &> /dev/null; then
echo "The IP address $ip_to_ping is unreachable."
else
echo "The IP address $ip_to_ping is reachable."
fi
fi