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.]
(Score: 2) by boltronics on Thursday January 17 2019, @02:39AM (7 children)
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!
(Score: 0) by Anonymous Coward on Thursday January 17 2019, @02:46AM (6 children)
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:
(Score: 2) by cubancigar11 on Thursday January 17 2019, @03:10AM (2 children)
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)
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]
Probably my fault though. I will take a deeper look later, thanks.
(Score: 2) by cubancigar11 on Thursday January 17 2019, @06:39AM
Oh yeah. There are two forks now, I use the classic one http://www.pogo.org.uk/~mark/xosview/ [pogo.org.uk] but default installation point to the new version 2.
(Score: 0) by Anonymous Coward on Thursday January 17 2019, @04:10AM (1 child)
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
Spending hours figuring out your own regex years later isn't any better.
(Score: 2) by boltronics on Friday January 18 2019, @03:00AM
In the case of the first regex, the input looks something like this:
So the regex used is the following:
The regex works like this:
for example:
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:
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.
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
extracts just the Tdie lines and then extracts just the temperature values from those. eg.
We can then easily put this on a single line like so:
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:
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!