Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 06-19-2009, 11:10 PM   #1
LQ Newbie
Registered: May 2009
Posts: 8

Rep: Reputation: 1
Running /sbin/rc from non-interactive script?


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,, like this:


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):
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 ...


Last edited by marco1475; 06-20-2009 at 11:20 PM. Reason: updated with more info
Old 06-23-2009, 04:43 PM   #2
LQ Newbie
Registered: May 2009
Posts: 8

Original Poster
Rep: Reputation: 1
So turns out that /sbin/rc is never supposed to get into the branch I copy&pasted above ... When the script is executed from an interactive console, RUNLEVEL is "" (i.e. empty). However, when it is executed from a non-iteractive console (ACPI script) on my machine, RUNLEVEL is suddenly "S". I don't know why that is, but it turned out to be a hacky solution: I simply set RUNLEVEL="" before I call /sbin/rc and now it works. It might be totally wrong and evil - I suspect I am leaking something somewhere or something is off that will come back and bite me - but it works, for now.

P.S.: If anyone knows why this would be or what a correct solution is, please let me know!


acpi, management, noninteractive, power, runlevel, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automating Interactive script soupbone38 Programming 1 04-16-2009 09:50 AM
BASH - How to open an interactive script from a non interactive script..... OldGaf Programming 4 06-29-2008 04:34 PM
shell script in non interactive way googlix Linux - General 6 11-13-2007 09:18 AM
Making an init script interactive valcaro SUSE / openSUSE 1 04-27-2007 03:05 PM
Please help with interactive script moosedaddy Linux - Newbie 3 12-08-2005 09:02 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:13 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration