Adding to torsmo display in dsl-nForum: DSL-N Topic: Adding to torsmo display in dsl-n started by: Juanito Posted by Juanito on Sep. 26 2007,13:32
The recent worldtime thread motivated me to add some details to torsmo in dsl-n - I got most of the way there, but a little help from the scripting brethren would go a long way...I modified .torsmorc to read:
The first problem I have is that cpufreq.sh/cpugov.sh return a value and a <cr> or <lf> or something which gives an empty line in the torsmo display. How do I prevent this? The second problem I have is that I would like to add more data from a command with a couple of possible outcomes:
How do I retrieve "standby" or "active/idle" from this? I realise the answer is out there in google but so far I just got confused... Posted by ^thehatsrule^ on Sep. 26 2007,14:59
1Can you edit those *.sh files? �It would be the ideal solution (look for echo or printf lines). �Otherwise if the extra newline is after the text you want, you can append ` | head -1 ` to get the first line of any stdout. �(actually I think the standard now is to use ` | head -n1 ` now, but both should work) 2 You probably want to use something more specific on your grep, such as ` | grep "drive state is:" ` then pipe that to some parsing utility... although you could probably implement everything in 1 command if you use a more powerful tool. �So in the end you could add something simple like ` | grep "drive state is:" | cut -21- ` or something more fancy. An alternative to 2 is to look in those scripts in /etc/init.d and see where they get their info from... where it may be more efficient to parse input from (esp. if you are going to keep running it via torsmo). Posted by Juanito on Sep. 27 2007,07:08
- Sorry, I didn't explain myself well there. These are files I created to be able to pass the output of a command to torsmo (a la .torsmo_ip). Thanks for the help, I'm moving nearer to a solution. If I use the commands directly from a terminal window, I get:
So "head -n1" has no effect - "head -c8" works for 1.60 GHz but not for 800 MHz which has one character less. Similiarly:
...works with "performance" and "conservative" but not with "ondemand", "userspace" or "powersave" Your suggestions for the grep statement worked well:
but then I have the same problem of the output moving onto the next line. I'll keep working on this - any additional suggestions would be welcome � Posted by ^thehatsrule^ on Sep. 27 2007,13:33
Oh.. you don't want any newlines at all.. misunderstood you on that. In your scripts, if you use echo, replace them with printf (or use the unused echo -n).But in general you could remove newlines, or just the last character... such as with ` | head -c-1 ` Posted by Juanito on Sep. 27 2007,16:38
I can see that "echo -n" or printf would do the trick if I had the information I need in a variable (eg $PATH) - so I guess I need to figure out how to pass the output from a command into a variable. So far I can see how to pass a constant to a variable (eg VAR=hello, echo -n {$VAR}) | head -c-1 (and variations thereof) results in the error "head: -1: invalid number of bytes" Edit: I'm guessing something like this will do it but I'm away from dsl-n at the moment:
Posted by ^thehatsrule^ on Sep. 27 2007,18:26
Afaik printf should be used over echo -n due to it being more standardized, (and therefore more portable).Heh, maybe negatives aren't supported in the busybox version... If you're using awk, you may as well do all of the parsing in it. Posted by Juanito on Sep. 28 2007,07:19
The awk thing seems to have fixed the problem - the three mini-scripts now look like this:
...and the excerpt from .torsmorc looks like this:
- after looking at the awk statement in .torsmo_ip I can believe you're right, but after staring at it for 30mins I wasn't feeling much enlightenment Posted by curaga on Sep. 28 2007,12:31
To pass the output to a var:VAR=`echo Yeah` Posted by WDef on Oct. 02 2007,13:31
In case it helps in future, to get rid of newlines in a pipe without invoking awk or sed or somesuch, do:
tr is probably more efficient (not that it probably matters much in this case). Re:
This can probably be contracted to:
Posted by Juanito on Oct. 05 2007,07:45
Thanks - the 3 mini-scripts now look like this:
|