The preferred way to do this is by creating a service
with systemd.
Adding script in rc.local
is the deprecated way.
- Create a script file wherever you wish. Ex:
~/scripts/disable-devices-as-wakeup.sh
.
#!/bin/bash
declare -a devices=(XHC OCH1 USB1 USB2) # <-- Add your entries here
for device in "${devices[@]}"; do
if grep -qw ^$device.*enabled /proc/acpi/wakeup; then
sudo sh -c "echo $device > /proc/acpi/wakeup"
fi
done
Test it by executing it from the terminal.
If everything is okay then let's make a service.
$ touch ~/scripts/disable-devices-as-wakeup.service
~/scripts/disable-devices-as-wakeup.service -
[Unit]
Description=Disable devices as wakeup
[Service]
ExecStart=/home/username/scripts/disable-devices-as-wakeup.sh
Type=oneshot
[Install]
WantedBy=multi-user.target
- Copy or move the service to
/etc/systemd/system/
.
$ sudo cp ~/scripts/disable-devices-as-wakeup.service /etc/systemd/system/
- Enable the service.
$ systemctl enable disable-devices-as-wakeup.service
- Restart the OS and check the status.
$ systemctl status disable-devices-as-wakeup.service
Detailed explanation found on https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/chap-managing_services_with_systemd