Hi,
I was trying to get a run level switch from "default" to my custom "battery" run level to work. I have the run level set up, it works fine - when I call "/sbin/rc battery" or "/sbin/rc default" in xterm, I get the desired result. But when I put it into a script, test.sh, like this:
Code:
#!/bin/bash
echo "TEST!" >> /etc/acpi/test.txt 2>&1
/sbin/rc battery >> /etc/acpi/test.txt 2>&1
and have ACPI call it through ac_adapter and battery events, it does nothing (run level doesn't get changed). When I execute the script from xterm, it works fine. I checked the ACPI events and they get triggered, so after I plug in my AC power cord or unplug it, I can see a new line with "TEST!" printed in /etc/acpi/test.txt ... so the script is definitely being called. But other than the "TEST!" the file is empty, so no error messages are piped in.
I suspect /sbin/rc is missing some environment variable it has access to in xterm (and is missing because the ACPI call is in non-interactive shell), but I have no idea which one. Any ideas why it doesn't work or what is going on?
Update: I tried copying over the output of "env" in a live console into the script (i.e. trying to manually set all environment variables) to no effect - "/sbin/rc battery" still did not execute. Then I thought maybe one of the scripts "/sbin/rc battery" could not be stopped or started and that was why it failed on me - again, no such luck. All scripts when stopped and then started manually did so as expected. I also looked at /sbin/rc to try and find out where it is failing (because despite my best tries, I cannot get the return value or any message from it) and I found out that it gets to where it is supposed to (as far as I can tell):
Code:
608: elif [[ ( ${RUNLEVEL} == "S" || ${RUNLEVEL} == "1" ) && ${argv1} != "single" ]]
609: then
610: level=$(awk -v level="${argv1}" '
611: $2 == level {
612: split($0, fields, ":")
613: print fields[2]
614: exit
615: }' /etc/inittab 2>/dev/null)
616: [[ -z ${level} ]] && level=3
617: /sbin/telinit "${level}"
618: exit 0
619: fi
It passes "level 3" off to /sbin/telinit and that is as far as I can go, because /sbin/telinit seems to be a binary file I cannot debug. Help please, I am seriously running out of ideas here ...
Thanks,
marco1475