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: 4, Interesting) by mmh on Thursday January 17 2019, @04:52AM (6 children)

    by mmh (721) on Thursday January 17 2019, @04:52AM (#787784)

    GNU Screen can handle this very easily, and has the added benefit it'll work even when you're not in the GUI.

    To use, first make sure you have screen installed, if you're using an dpkg based distro, the command: "sudo apt install screen" should get it.

    Next Create a file called 'sensors.screen' and put the following content in it:

    layout new
    screen -t 'nethogs' 0 /bin/bash -c 'sudo nethogs'
    split
    focus next
    screen -t 'sensors' 1 /bin/bash -c 'watch -n1 sensors'
    split -v
    focus next
    screen -t 'inxi' 2 /bin/bash -c 'inxi -s'
    resize -8

    Finally run screen: screen -c sensors.screen

    You should really read the manual to screen if you plan on using this alot. Short version, use the key combo: CTRL+A \ to exit out of the entire thing.

    Starting Score:    1  point
    Moderation   +2  
       Interesting=1, Informative=1, Total=2
    Extra 'Interesting' Modifier   0  
    Karma-Bonus Modifier   +1  

    Total Score:   4  
  • (Score: 0) by Anonymous Coward on Thursday January 17 2019, @04:34PM

    by Anonymous Coward on Thursday January 17 2019, @04:34PM (#787922)

    I think this is the winner for being the easiest to get working. Its already set up and working. Now I just need to play with the layout a bit.

  • (Score: 0) by Anonymous Coward on Thursday January 17 2019, @04:55PM (4 children)

    by Anonymous Coward on Thursday January 17 2019, @04:55PM (#787932)

    Someone else suggested this regex to remove some of the redundant text:

    watch -n1 "echo -n 'Tdie ' ; sensors | grep Tdie | sed 's/^[^:]*:\ *\([^\ ]*\).*$/\1/' | xargs echo"

    Do you know off the top of your head how to deal with the nested quotes when using screen?

    This works fine:

    screen -t 'sensors' 1 /bin/bash -c 'watch -n1 "sensors | grep Tdie"'

    All variants I tried on this are blank:

    screen -t 'sensors' 1 /bin/bash -c 'watch -n1 "echo -n 'Tdie ' ; sensors | grep Tdie | sed 's/^[^:]*:\ *\([^\ ]*\).*$/\1/' | xargs echo"'

    • (Score: 3, Informative) by mmh on Thursday January 17 2019, @06:19PM (3 children)

      by mmh (721) on Thursday January 17 2019, @06:19PM (#787970)

      It would be possible to nest the quotes and get it working, but that'd be a giant pain to do and more of a pain in the future edit. A better solution would be to stick it in a different script and call it:

      Create ~/bin folder if it doesn't exists:

      mkdir -p $HOME/bin/

      Take your commands and pipe and save them to fancy-schmancy-sensors.sh:

      #!/bin/bash
      echo -n 'Tdie '
      sensors | grep Tdie | sed 's/^[^:]*:\ *\([^\ ]*\).*$/\1/' | xargs echo

      Make your new script executable:

      chmod +x $HOME/bin/fancy-schmancy-sensors.sh

      Update the previously created sensors.screen file to call fancy-schmancy-sensors.sh:

      layout new
      screen -t 'nethogs' 0 /bin/bash -c 'sudo nethogs'
      split
      focus next
      screen -t 'sensors' 1 /bin/bash -c 'watch -n1 ${HOME}/bin/fancy-schmancy-sensors.sh'
      split -v
      focus next
      screen -t 'inxi' 2 /bin/bash -c 'inxi -s'
      resize -8

      • (Score: 0) by Anonymous Coward on Thursday January 17 2019, @06:39PM

        by Anonymous Coward on Thursday January 17 2019, @06:39PM (#787976)

        Perfect. Thanks. Now to the layout...

      • (Score: 0) by Anonymous Coward on Thursday January 17 2019, @06:50PM (1 child)

        by Anonymous Coward on Thursday January 17 2019, @06:50PM (#787980)

        What do you use when you search for help? Screen is an awful name for that purpose...

        Basically I am trying to search for how to adjust the font size per panel and can't find anything. I assume that's because my results are polluted by general questions about increasing font size on the monitor.

        • (Score: 2) by mmh on Thursday January 17 2019, @07:15PM

          by mmh (721) on Thursday January 17 2019, @07:15PM (#787996)

          You'll get best results searching "GNU Screen" (including the quotes)