From d9f57ef324ec5e031661f3249c94740b5b046934 Mon Sep 17 00:00:00 2001 From: Eliezer Croitoru Date: Tue, 19 Nov 2024 18:48:46 +0200 Subject: [PATCH] 2 --- Makefile | 2 ++ gen-and-install-service.sh | 13 +++++++++++++ ping-host-target.service | 9 +++++++++ 3 files changed, 24 insertions(+) create mode 100644 gen-and-install-service.sh create mode 100644 ping-host-target.service diff --git a/Makefile b/Makefile index 1fe68a9..db961f3 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ all: echo OK +install: + cp -vf ping-host.sh /usr/local/bin/ diff --git a/gen-and-install-service.sh b/gen-and-install-service.sh new file mode 100644 index 0000000..149f83a --- /dev/null +++ b/gen-and-install-service.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +HOST="$1" + +set -x +echo "${HOST}" | egrep "^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$" +if [ "$?" -eq "0" ] +then + cat ping-host-target.service | sed -e "s@##TARGET##@${HOST}@g" > "/etc/systemd/system/ping-host-${HOST}.service" + systemctl daemon-reload +fi + +set +x diff --git a/ping-host-target.service b/ping-host-target.service new file mode 100644 index 0000000..6d21f60 --- /dev/null +++ b/ping-host-target.service @@ -0,0 +1,9 @@ +[Unit] +Description=Ping a host service + +[Service] +Type=simple +ExecStart=/bin/bash /usr/local/bin/ping-host.sh ##TARGET## + +[Install] +WantedBy=multi-user.target