From efc4f18c43a6dfee3c6e3d3fa172fee5c36aa764 Mon Sep 17 00:00:00 2001 From: Lorenzo Iovino Date: Thu, 6 Jun 2024 18:12:08 +0200 Subject: [PATCH] Update shutdown-delemaco.sh --- shutdown-delemaco.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/shutdown-delemaco.sh b/shutdown-delemaco.sh index 8b13789..f77964d 100644 --- a/shutdown-delemaco.sh +++ b/shutdown-delemaco.sh @@ -1 +1,62 @@ +#!/bin/bash +SERVER="delemaco" # Server to ping + +echo "Content-type: text/html" +echo +# Function to ping the server and generate HTML output +generate_html() { + local server=$1 + + # Ping the server (send 1 packet and wait for 1 second) + ping -c 1 -W 1 "$server" > /dev/null 2>&1 + if [ $? -eq 0 ]; then + status="Shutdown" + color="gray" + sudo shutdown + else + status="Offline" + color="red" + fi + + + # Generate HTML content + HTML_CONTENT=$(cat < + + + + + Server Status + + + +
+ Server $server is currently $status. +
+ + +EOL +) + echo "$HTML_CONTENT" +} + +# Run the function and save the output to a variable +HTML_OUTPUT=$(generate_html "$SERVER") + +# Print the HTML content +echo "$HTML_OUTPUT"