Skip to content

Instantly share code, notes, and snippets.

@sacsbrainz
Last active March 26, 2024 22:23
Show Gist options
  • Save sacsbrainz/e6880bcc3777809133c4becc4ea7a587 to your computer and use it in GitHub Desktop.
Save sacsbrainz/e6880bcc3777809133c4becc4ea7a587 to your computer and use it in GitHub Desktop.
Automatic wakeup on laptop running linux

kill-enabled.sh

#!/bin/bash

# Check if the script is run as root
if [ "$(id -u)" -ne 0 ]; then
    echo "This script must be run as root" 1>&2
    exit 1
fi

# Disable all enabled wakeup devices
while read -r line; do
    device=$(echo "$line" | awk '{print $1}')
    status=$(echo "$line" | awk '{print $3}')
    if [ "$status" == "*enabled" ]; then
        echo "Disabling wakeup device: $device"
        echo "$device" > /proc/acpi/wakeup
    fi
done < /proc/acpi/wakeup

save the above file then if you are using systemd you can create a service that exec the script

cd /etc/systemd/system

then create the below file

acpi-wake.service

[Unit]
Description=Disable Wakeup Devices
After=multi-user.target

[Service]
Type=oneshot
User=root
Group=root
ExecStart=/home/sacs/kill-enabled.sh

[Install]
WantedBy=multi-user.target

lastly

sudo systemctl daemon-reload
sudo systemctl start acpi-wake.service
sudo systemctl enable acpi-wake.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment