DSL-N :: Adding to torsmo display in dsl-n

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-info -mf
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...

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)

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

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.

Code Sample
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor | head -c11

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

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

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 `

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}'

Next Page...
original here.