fedora-csb-system-manager
1#!/usr/bin/env bash
2
3# wake-up.sh - A simple Wake-on-LAN script using the 'wol' command
4
5# --- Configuration: Machine Names and MAC Addresses ---
6# IMPORTANT: Replace these with your actual machine names and MAC addresses.
7# For Bash 4.0+ (most modern Linux systems)
8declare -A MACHINES=(
9 ["shikoku"]="2c:4d:54:4c:a0:85"
10 ["kobe"]="e8:6a:64:0f:98:06"
11 ["sakhalin"]="b4:2e:99:b1:f2:cb"
12)
13
14# --- End Configuration ---
15
16# Check if a machine name was provided as an argument
17if [ -z "$1" ]; then
18 echo "Usage: $0 <machine_name>"
19 echo "Example: $0 shikoku"
20 echo ""
21 echo "Available machines:"
22 for machine in "${!MACHINES[@]}"; do
23 echo "- $machine"
24 done
25 exit 1
26fi
27
28MACHINE_NAME="$1"
29MAC_ADDRESS="${MACHINES[$MACHINE_NAME]}"
30
31# Check if the machine name exists in our configuration
32if [ -z "$MAC_ADDRESS" ]; then
33 echo "Error: Machine '$MACHINE_NAME' not found in configuration."
34 echo "Available machines:"
35 for machine in "${!MACHINES[@]}"; do
36 echo "- $machine"
37 done
38 exit 1
39fi
40
41echo "Attempting to wake up '$MACHINE_NAME' with MAC address '$MAC_ADDRESS'..."
42
43# Execute the wol command
44# -p 9: Specifies port 9 (a common WOL port, though 7 or 0 might also work for some devices)
45# -v: Verbose output from the wol command (optional, can be removed)
46wol -p 9 -v "$MAC_ADDRESS"
47
48if [ $? -eq 0 ]; then
49 echo "Wake-on-LAN magic packet sent successfully to '$MACHINE_NAME'."
50else
51 echo "Error: Failed to send Wake-on-LAN magic packet to '$MACHINE_NAME'."
52 echo "Please ensure 'wol' command is installed and you have network connectivity."
53fi