Create wol-delemaco.sh

This commit is contained in:
Lorenzo Iovino 2024-06-06 17:19:31 +02:00 committed by GitHub
parent e387849c2f
commit ba6ed6633b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

63
wol-delemaco.sh Normal file
View file

@ -0,0 +1,63 @@
#!/bin/bash
# Configuration
SERVER="delemaco" # Server to ping
#wakeonlan b8:cb:29:a1:f3:88
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="Online"
color="green"
else
status="Offline"
color="red"
wakeonlan b8:cb:29:a1:f3:88
fi
# Generate HTML content
HTML_CONTENT=$(cat <<EOL
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Server Status</title>
<style>
body {
background-color: $color;
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.status {
font-size: 72px;
color: white;
}
</style>
</head>
<body>
<div class="status">
Server <strong>$server</strong> is currently $status.
</div>
</body>
</html>
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"