How to trigger a command on Linux when disconnected from power

Hi

I wrote a guide explaining how to soft implement an equivalent to BusKill using a power supply event to trigger a command in dom0.

Feel free to ask if you have questions or Qubes OS specific implementation questions :slight_smile:

8 Likes

For udev rules you should add

ENV{POWER_SUPPLY_TYPE}=="Mains"

because there is alot of devices in SUBSYTEM=="power_supply" with envinriment POWER_SUPPLY_ONLINE, including usb

2 Likes

Thank you very much for bringing this, I fixed my guide :slight_smile:

I tested it on my laptop too, works fine with this extra bit added.

1 Like

On Qubes OS, this could easily be extended if you want to run a command only if a given wifi SSID is not found around (like, you disconnect the computer and you are not at home / office).

#!/bin/sh
if ! qvm-run -u user sys-net "nmcli device wifi list | grep MY-WIFI-SSID"
then
    systemctl poweroff
fi
1 Like