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
  • Try executing a script when the lid is closed and implement what you want in the script https://askubuntu.com/questions/525995/catch-lid-close-and-open-events – Katu May 02 '18 at 13:15
  • Yes thus can be done. Hopefully someone posts an answer today. – WinEunuuchs2Unix May 02 '18 at 15:15

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,593
  • 26
  • 42
  • This is much more elegant than what I had written so far. It doesn't seem to be working though. I'm not exactly sure where to look to debug this. I wonder if it has anything to do with requiring authentication. When I run systemctl suspend from a shell it says Authentication is required to set a wall message Authenticating as myusername followed by a password prompt. I have to do this for both ==== AUTHENTICATING FOR org.freedesktop.login1.set-wall-message === and ==== AUTHENTICATING FOR org.freedesktop.login1.suspend === to get it to suspend. – mandelbug May 02 '18 at 17:57
  • @JoshI I have edited the answer with some ideas that I hope will help you debugging your problem. – Katu May 02 '18 at 21:21