Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (2) </ [1] 2 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Adding to torsmo display in dsl-n, Some help required< Next Oldest | Next Newest >
Juanito Offline





Group: Members
Posts: 1601
Joined: Sep. 2005
Posted: Sep. 26 2007,13:32 QUOTE

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:
Code Sample
${color red}$hr
${color grey}Uptime:   $color $uptime
${color #ddd}Battery:  $color ${battery}
${color #ddd}CPU Temp: $color ${acpitemp}degC
${color grey}CPU Freq: $color ${execi 180 ~/.cpufreq.sh}
${color grey}CPU Govn: $color ${execi 180 ~/.cpugov.sh}
${color green}$hr$color
[.cpufreq.sh]
cpufreq-info -mf
[.cpugov.sh]
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

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:
Code Sample
$ sudo /etc/init.d/laptop-mode status | grep drive
   drive state is:  standby
(NOTE: drive settings affected by Laptop Mode cannot be retrieved.)

$ sudo /etc/init.d/laptop-mode status | grep drive
   drive state is:  active/idle
(NOTE: drive settings affected by Laptop Mode cannot be retrieved.)

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...
Back to top
Profile PM 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Sep. 26 2007,14:59 QUOTE

1
Can 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).
Back to top
Profile PM 
Juanito Offline





Group: Members
Posts: 1601
Joined: Sep. 2005
Posted: Sep. 27 2007,07:08 QUOTE

Quote
Can you edit those *.sh files?

- 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:
Code Sample
$ cpufreq-info -mf | head -n1
1.60 GHz
$ cpufreq-info -mf | head -c8
1.60 GHzdsl@dslbox:~$

So "head -n1" has no effect - "head -c8" works for 1.60 GHz but not for 800 MHz which has one character less.

Similiarly:
Code Sample
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor | head -c11
performancedsl@dslbox:~$

...works with "performance" and "conservative" but not with "ondemand", "userspace" or "powersave"

Your suggestions for the grep statement worked well:
Code Sample
$ sudo /etc/init.d/laptop-mode status | grep "drive state is:" | cut -b22-
active/idle

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  :)
Back to top
Profile PM 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Sep. 27 2007,13:33 QUOTE

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 `
Back to top
Profile PM 
Juanito Offline





Group: Members
Posts: 1601
Joined: Sep. 2005
Posted: Sep. 27 2007,16:38 QUOTE

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:
Code Sample
$ sudo /etc/init.d/laptop-mode status | grep "drive state is:" | awk '{printf $1}'
Back to top
Profile PM 
9 replies since Sep. 26 2007,13:32 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (2) </ [1] 2 >/
reply to topic new topic new poll
Quick Reply: Adding to torsmo display in dsl-n

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code