From 79d1fce98cf519a224f8b53fc6690ed070040374 Mon Sep 17 00:00:00 2001 From: uvok cheetah Date: Thu, 4 Apr 2024 21:22:13 +0200 Subject: Instal jq, add online monitor --- roles/common/files/onmon.service | 10 ++++++++++ roles/common/files/onmon.sh | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 roles/common/files/onmon.service create mode 100644 roles/common/files/onmon.sh (limited to 'roles/common/files') diff --git a/roles/common/files/onmon.service b/roles/common/files/onmon.service new file mode 100644 index 0000000..8ac3020 --- /dev/null +++ b/roles/common/files/onmon.service @@ -0,0 +1,10 @@ +[Unit] +Description=Online monitor +Requires=network-online.target +After=network-online.target + +[Service] +ExecStart=/usr/local/bin/onmon.sh + +[Install] +WantedBy=default.target diff --git a/roles/common/files/onmon.sh b/roles/common/files/onmon.sh new file mode 100644 index 0000000..66a7974 --- /dev/null +++ b/roles/common/files/onmon.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +ping -nq -W 1 -c 1 1.1.1.1 > /dev/null 2>&1 +state=$? +oldstate=$state + +while true; do + ping -nq -W 1 -c 1 1.1.1.1 > /dev/null 2>&1 + state=$? + + if [[ $oldstate -ne $state ]]; then + if [[ $state -eq 0 ]]; then + echo "Device went back online" + else + echo "Device went offline" + fi + fi + + oldstate=$state + sleep 5 +done -- cgit v1.2.3