3

I know you can disable standby when you close your laptop lid, but is it possible to not have it go on standby if ethernet is plugged in?

So basically, whether on battery power or not I need it to work like this:

If laptop shell closed
    If ethernet not plugged in
        Go to standby
    Else
        Don't go to standby, ever

Is there a way to acheive this?

mandelbug
  • 131

1 Answers1

1

Ok, with some info from other answers, you can try this untested method:

From Catch lid close and open events

  • The script you want to call when the lid opens or closes has to be stored
    in /etc/acpi/lid.sh.

  • Then there has to be created the correct file /etc/acpi/events/lm_lid with the content as follows:

    event=button/lid.*
    action=/etc/acpi/lid.sh
    
  • Reboot your system to let this take effect. Or maybe it is enough to restart your ACPI using

    sudo /etc/init.d/acpid restart
    

From https://unix.stackexchange.com/questions/252002/help-testing-special-file-in-sys-class-net and How can I suspend/hibernate from command line? the /etc/acpi/lid.sh script will look like this (change yournetworkcardname for your name of your network card. Use ifconfig to find it). You can choose between suspend or hibernate.

#!/bin/bash
if [ "$(head -c1 /sys/class/net/yournetworkcardname/carrier)" -eq 0 ]; then
    systemctl suspend
fi

Test the script with bash -x /etc/acpi/lid.sh and make sure it works. You might have to add the following to run the script as sudo without being prompted with a password, from https://unix.stackexchange.com/questions/18830/how-to-run-a-specific-program-as-root-without-a-password-prompt:

myusername ALL = (root) NOPASSWD: /etc/acpi/lid.sh

Maybe you will also have to call the script in the action with sudo.

Katu
  • 3,663