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 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!
    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

    Total Score:   2