Stories
Slash Boxes
Comments

SoylentNews is people

posted by martyb on Thursday January 17 2019, @01:45AM   Printer-friendly
from the automation++ dept.

Hi all,

I have been learning linux and have a secondary monitor that I wanted to use for showing some sensor data. Currently I need to manually enter in three commands and then arrange my windows each time I want to look at (and start-up, etc). I am using the nethogs, inxi, and lm-sensors libraries:

sudo nethogs
watch -n1 "inxi -s"
watch -n1 "sensors | grep Tdie"

The end result looks something like this:
https://i.ibb.co/TgWXKSn/sensors.png

Is it possible/easy to script the opening of these three terminal windows and position them onto a specific monitor? Or is there a completely different better way to go about this?

Also, is there a way for me to custom arrange the data on the screen? Eg, could I put the sensors "Tdie" data into two columns and remove the "high = +70.0 C" info?

[Beyond this specific case, is there a general solution with, say, a directory containing a separate shell script for launching each program, with a master script that specifies terminal width/height as well as (x,y) coordinates? --Ed.]


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 2) by boltronics on Thursday January 17 2019, @02:39AM (7 children)

    by boltronics (580) on Thursday January 17 2019, @02:39AM (#787725) Homepage Journal

    Except I changed the command to use "Core" on my system instead of "Tdie", so the output for you should actually be something like:

    Tdie: +40.0°C
    Tdie: +40.0°C
    Tdie: +41.0°C
    Tdie: +36.0°C

    which I believe is what you requested.

    --
    It's GNU/Linux dammit!
    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

    Total Score:   2  
  • (Score: 0) by Anonymous Coward on Thursday January 17 2019, @02:46AM (6 children)

    by Anonymous Coward on Thursday January 17 2019, @02:46AM (#787729)

    Yes, perfect. Thanks. I have no idea what that regex is doing but it works and I should be able to use it as a template for any future info. Eg I want to see cpu clock speed by thread eventually:

    watch -n1 "cat /proc/cpuinfo | grep "MHz""

    • (Score: 2) by cubancigar11 on Thursday January 17 2019, @03:10AM (2 children)

      by cubancigar11 (330) on Thursday January 17 2019, @03:10AM (#787743) Homepage Journal

      You might be interested in xosview. There is a classic version.
      Also, automatic window positioning can be achieved by fvwm.

      My person fvwm config file does all these actually, but it has been called extremely ugly to look at, so... :) It was derived from Tavis Ormandy's config (http://taviso.decsystem.org/img/screenshot.png https://github.com/zy/zy-fvwm/blob/master/fvwmrc/taviso.fvwm2rc). [github.com] Just FYI...

      • (Score: 0) by Anonymous Coward on Thursday January 17 2019, @03:24AM (1 child)

        by Anonymous Coward on Thursday January 17 2019, @03:24AM (#787753)

        It looks interesting. I tried it and couldn't get the option to show the temperature to work though. Even trying the option in the docs didn't work: http://xosview.sourceforge.net/documentation.html [sourceforge.net]

        user@host:~$ xosview -o "memFreeColor: purple"
        Ignoring unknown option '-o'.
        Ignoring unknown option 'memFreeColor: purple'.

        Probably my fault though. I will take a deeper look later, thanks.

    • (Score: 0) by Anonymous Coward on Thursday January 17 2019, @04:10AM (1 child)

      by Anonymous Coward on Thursday January 17 2019, @04:10AM (#787774)

      It's usually better to stick to grep/awk pipes than use regex you don't understand. You might want to modify the script later, and spending hours figuring out something someone else wrote is infuriating.

      cpucount=$(awk '/MHz/' /proc/cpuinfo | wc -l)

      for cpu in $(seq 1 ${cpucount})
              do
                      grep MHz /proc/cpuinfo | awk 'NR=='${cpu}'{print "CPU'${cpu}': " $4 " MHz"}'
              done

      [ac][~]:sh cpuinfo.sh
      CPU1: 3782.316 MHz
      CPU2: 3593.783 MHz
      CPU3: 3596.303 MHz
      CPU4: 3691.905 MHz

      • (Score: 2) by Farkus888 on Friday January 18 2019, @12:31AM

        by Farkus888 (5159) on Friday January 18 2019, @12:31AM (#788087)

        Spending hours figuring out your own regex years later isn't any better.

    • (Score: 2) by boltronics on Friday January 18 2019, @03:00AM

      by boltronics (580) on Friday January 18 2019, @03:00AM (#788128) Homepage Journal

      In the case of the first regex, the input looks something like this:

      Tdie:         +51.8C   (high = +70.0°C)

      So the regex used is the following:

      $ sed 's/^\(.*:\)\ *\([^\ ]*\).*$/\1 \2/'

      The regex works like this:

      's/<pattern>/<replacement>/'

      for example:

      $ echo cycling | sed 's/cycl/runn/'
      running

      The first ^ matches from the start of the line. The $ matches up to the end of the line.

      The \(<something>\) puts whatever is contained within into a variable. We have two of them, and they are referenced by \1 and \2 in the replacement test.

      .*: matches all characters up to and including the last colon in the input string.

      [^\ ]* matches anything that is not a space, so will not match anything past a space.

      The last .* just matches whatever is remaining.

      So basically we're taking Tdie: and putting it into \1. Then we take the next word (separated by one or more spaces) and put that into \2. Then we output just those with a spare separating them as the replacement text for the whole thing. That gives us:

      Tdie: +40.0°C
      Tdie: +40.0°C
      Tdie: +41.0°C
      Tdie: +36.0°C

      It's actually really easy to read most simple regular expressions such as this one when you understand the syntax.

      So now that you understand the first regex, the second one should make a lot more sense.

      $ sed 's/^[^:]*:\ *\([^\ ]*\).*$/\1/'

      We're using the same s/<pattern>/<replacement>/ style, and start matching from the start of the line (^). We then match anything that is not a colon character (:). We then match a colon and one or more spaces. We then store the next word in a variable (\1) - where "word" is defined as anything up until the next space character. Then we match anything else up until the end of the line. This entire match gets replaced with the contents of \1, which in our case is going to be the temperature. eg. +40.0°C

      So

      sensors | grep Tdie | sed 's/^[^:]*:\ *\([^\ ]*\).*$/\1/'

      extracts just the Tdie lines and then extracts just the temperature values from those. eg.

      +38.0°C
      +37.0°C
      +40.0°C
      +33.0°C

      We can then easily put this on a single line like so:

      $ sensors | grep Tdie | sed 's/^[^:]*:\ *\([^\ ]*\).*$/\1/' | xargs echo
      +38.0°C +37.0°C +40.0°C +34.0°C

      We could also write it like this if we want (I just put Tdie: at the end) so the title of the data is on the same line:

      sensors | grep Tdie | sed 's/^[^:]*:\ *\([^\ ]*\).*$/\1/' | xargs echo Tdie:
      Tdie: +38.0°C +37.0°C +40.0°C +34.0°C

      Then you can wrap all that up as an argument to the watch command.

      I hope this helps you to understand and enjoy using regular expressions!

      --
      It's GNU/Linux dammit!