35 lines
1.2 KiB
Bash
35 lines
1.2 KiB
Bash
|
#!/bin/bash
|
||
|
FILE_PATH=/data/stupid-natalieee.net-uptime-tracker
|
||
|
|
||
|
function other_websites_reacheable() {
|
||
|
# ensure it is not reacheable because natalie issue, not network issue
|
||
|
for site in {'google.com','duckduckgo.com','mozilla.org'}; do
|
||
|
ping -W1 -c1 "${site}" > /dev/null 2>&1 || return 1;
|
||
|
done
|
||
|
}
|
||
|
|
||
|
function set_state() {
|
||
|
sed -i "s/${1}/${2}/" $FILE_PATH
|
||
|
}
|
||
|
|
||
|
function update_count() {
|
||
|
set_state "$(grep "${1} count: " "${FILE_PATH}")" "${1} count: $(($(grep "${1} count: " "${FILE_PATH}" | cut -d: -f2) + 1))"
|
||
|
}
|
||
|
|
||
|
ping -W1 -c1 natalieee.net > /dev/null 2>&1 && {
|
||
|
# natalieee.net reacheable
|
||
|
set_state "$(grep 'last update:' "${FILE_PATH}")" "last update: up"
|
||
|
update_count 'up'
|
||
|
} || {
|
||
|
# natalieee.net unreacheable or ping error
|
||
|
other_websites_reacheable && {
|
||
|
update_count 'down'
|
||
|
date +"natalieee.net unreacheable %s" >> "${FILE_PATH}"
|
||
|
set_state "$(grep 'last update:' "${FILE_PATH}")" 'last update: down (ping failed to only natalieee.net)'
|
||
|
} || {
|
||
|
update_count 'unknown'
|
||
|
date +"natalieee.net and other domains unreacheable %s" >> "${FILE_PATH}"
|
||
|
set_state "$(grep 'last update:' "${FILE_PATH}")" 'last update: down (ping failed to natalieee.net and some other domain(s))'
|
||
|
}
|
||
|
}
|