I'm trying to change some settings with the help of udev when i plug in and out the ac adopter but cant seem to get it to run. I'm running ubuntu 15.04 and this is what I've got:
sudo systemctl status udev ● systemd-udevd.service - udev Kernel Device Manager Loaded: loaded (/lib/systemd/system/systemd-udevd.service; static; vendor preset: enabled) Active: active (running) since lör 2015-05-02 20:28:42 CEST; 2h 3min ago Docs: man:systemd-udevd.service(8) man:udev(7) Main PID: 293 (systemd-udevd) CGroup: /system.slice/systemd-udevd.service └─293 /lib/systemd/systemd-udevd
agni% ls -l /etc/udev/rules.d/50* -rw-r--r-- 1 root root 122 maj 2 20:25 /etc/udev/rules.d/50-kappa.rules
This is what the rule contains i have tried a couple of different things but this is whats in it currently, and from what I understand it should work
cat /etc/udev/rules.d/50-kappa.rules ACTION=="change", SUBSYSTEM=="power_supply", RUN+="/usr/local/bin/power-change.sh true"
and the script that should run
ls -l /usr/local/bin/power-change.sh -rwxr-xr-x 1 root root 255 maj 2 17:24 /usr/local/bin/power-change.sh
cat /usr/local/bin/power-change.sh set_ac() { echo -e "$(date)\nAC CONNECTED" > /home/kempe/test2.txt } set_bat() { echo -e "$(date)\nAC DISCONNECTED" > /home/kempe/test2.txt } case $1 in true) set_ac ;; false) set_bat ;; *) exit 1 ;; esac exit 0
And this is what i have done to try to make it run with out any luck
sudo udevadm control --reload #no effect sudo udevadm trigger # no effect sudo reboot # no effect :)
udevadm monitor --property monitor will print the received events for: UDEV - the event which udev sends out after rule processing KERNEL - the kernel uevent KERNEL[816.963544] change /devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/power_supply/ADP1 (power_supply) ACTION=change DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/power_supply/ADP1 POWER_SUPPLY_NAME=ADP1 POWER_SUPPLY_ONLINE=0 SEQNUM=2847 SUBSYSTEM=power_supply UDEV [816.966150] change /devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/power_supply/ADP1 (power_supply) ACTION=change DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/power_supply/ADP1 POWER_SUPPLY_NAME=ADP1 POWER_SUPPLY_ONLINE=0 SEQNUM=2847 SUBSYSTEM=power_supply USEC_INITIALIZED=6963257 KERNEL[817.171654] change /devices/virtual/backlight/mba6x_backlight (backlight) ACTION=change DEVPATH=/devices/virtual/backlight/mba6x_backlight SEQNUM=2848 SOURCE=sysfs SUBSYSTEM=backlight UDEV [817.174385] change /devices/virtual/backlight/mba6x_backlight (backlight) ACTION=change DEVPATH=/devices/virtual/backlight/mba6x_backlight SEQNUM=2848 SOURCE=sysfs SUBSYSTEM=backlight SYSTEMD_WANTS=systemd-backlight@backlight:mba6x_backlight.service TAGS=:systemd: USEC_INITIALIZED=8174
If i run the script directly from terminal it works fine so there is no problem there
/usr/local/bin/power-change.sh true agni% cat /home/kempe/test2.txt -e lör 2 maj 2015 23:06:52 CEST AC CONNECTED
Any suggestions?
#!/bin/sh ... Where is the hashbang my friend?
The hashbang is missing in the script:
source: Writing udev rules
Another way, call it with
/bin/sh
I was wrongly looking for what going on in the rule for around two hours. That a lesson for me too.
BTW, You can debug and test your udev setup.