Skip to content

Instantly share code, notes, and snippets.

@CarlosRA97
Created January 6, 2022 16:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarlosRA97/9224528010cdbc96be8dc7537affb1d4 to your computer and use it in GitHub Desktop.
Save CarlosRA97/9224528010cdbc96be8dc7537affb1d4 to your computer and use it in GitHub Desktop.
This is bash script setup the wake on lan functionality on fedora systems using the nmcli command. it was extracted from a forum (https://forums.fedoraforum.org/showthread.php?322977-Making-WoL-persistent)
#!/bin/bash
#
clear
echo
echo
echo "Details of connections:"
echo "=================================================================================="
nmcli con show
CONNECTIONS=()
while IFS= read -r line; do
CONNECTIONS+=( "$line" )
done < <( nmcli -g name con )
echo
echo
echo "Connection Selections: "
echo "=================================================================================="
for i in ${!CONNECTIONS[@]}; do
echo "$i. ${CONNECTIONS[$i]}"
done
# Grab the size fo the array for later user selection test
len=$(expr ${#CONNECTIONS[@]} - 1)
echo
echo
echo
read -p "Please select the number of the connection you wish to enable WOL for: " DEVICE_SELECTION
echo
echo
# Quick user selection test if valid
if [[ DEVICE_SELECTION -gt $len ]]; then
echo "Invalid selection... Exiting..."
exit 1
fi
# Print out the current connection status
STATUS=$(nmcli c show "${CONNECTIONS[$DEVICE_SELECTION]}" | grep wake-on-lan: | awk '{print $2}')
echo "${CONNECTIONS[$DEVICE_SELECTION]} - WOL connection status: $STATUS"
echo
echo
echo "Setting 'magic' - Enabling wake on lan..."
nmcli c modify "${CONNECTIONS[$DEVICE_SELECTION]}" 802-3-ethernet.wake-on-lan magic
echo "Done."
echo
STATUS=$(nmcli c show "${CONNECTIONS[$DEVICE_SELECTION]}" | grep wake-on-lan: | awk '{print $2}')
echo "Updated '${CONNECTIONS[$DEVICE_SELECTION]}' WOL connection status to: $STATUS"
echo "Enabling wake on lan for connection '${CONNECTIONS[$DEVICE_SELECTION]}' complete."
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment