First
This commit is contained in:
72
Mon.sh
Executable file
72
Mon.sh
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env bash
|
||||
# Webhost Availability Monitor - Single File - Loop
|
||||
# user only. keine root.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
INTERVAL=60
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
LOG_DIR="$ROOT_DIR/logs"
|
||||
HOSTS_FILE="$ROOT_DIR/hosts.txt"
|
||||
SEP=';'
|
||||
|
||||
timestamp_iso() {
|
||||
date -Iseconds
|
||||
}
|
||||
|
||||
ensure_dirs() {
|
||||
mkdir -p "$LOG_DIR"
|
||||
}
|
||||
|
||||
current_logfile() {
|
||||
printf "%s/%s.csv" "$LOG_DIR" "$(date +%F)"
|
||||
}
|
||||
|
||||
write_header_if_needed() {
|
||||
local file="$1"
|
||||
if [ ! -f "$file" ] || [ ! -s "$file" ]; then
|
||||
printf "timestamp${SEP}label${SEP}http_code\n" >>"$file"
|
||||
fi
|
||||
}
|
||||
|
||||
stop_requested=0
|
||||
_on_exit() {
|
||||
stop_requested=1
|
||||
printf "\nstop received. exit after current batch\n" >&2
|
||||
}
|
||||
trap _on_exit INT TERM
|
||||
|
||||
ensure_dirs
|
||||
|
||||
printf "loop start. 60s. logs dir: %s\n" "$LOG_DIR"
|
||||
|
||||
while [ "$stop_requested" -eq 0 ]; do
|
||||
logfile="$(current_logfile)"
|
||||
write_header_if_needed "$logfile"
|
||||
|
||||
while IFS= read -r line; do
|
||||
[ -z "$line" ] && continue
|
||||
case "$line" in \#*) continue ;; esac
|
||||
|
||||
IFS='|' read -r label url expected <<<"$line"
|
||||
|
||||
ts="$(timestamp_iso)"
|
||||
set +o errexit
|
||||
code="$(curl -sS -o /dev/null -w "%{http_code}" --max-time 10 -L "$url" 2>/dev/null)" || code="000"
|
||||
set -o errexit
|
||||
|
||||
printf "%s%s%s%s%s\n" "$ts" "$SEP" "$label" "$SEP" "$code" >>"$logfile"
|
||||
done <"$HOSTS_FILE"
|
||||
|
||||
# interruptable sleep
|
||||
waited=0
|
||||
while [ "$waited" -lt "$INTERVAL" ] && [ "$stop_requested" -eq 0 ]; do
|
||||
sleep 1
|
||||
waited=$((waited+1))
|
||||
done
|
||||
done
|
||||
|
||||
printf "exit\n"
|
||||
2
hosts.txt
Normal file
2
hosts.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
google|https://www.google.com|200
|
||||
Authentik-Tim|https://auth.st-server.org|200
|
||||
5
logs/2025-11-10.csv
Normal file
5
logs/2025-11-10.csv
Normal file
@@ -0,0 +1,5 @@
|
||||
timestamp;label;http_code
|
||||
2025-11-10T12:23:06+00:00;google;200
|
||||
2025-11-10T12:23:07+00:00;Authentik-Tim;503
|
||||
2025-11-10T12:24:08+00:00;google;200
|
||||
2025-11-10T12:24:08+00:00;Authentik-Tim;503
|
||||
|
Reference in New Issue
Block a user