I'm running Ubuntu server 16.04, that I SSH into.

I am looking for a way to make the watch command monitor multiple things but running into a problem.

I have a working function that monitors my CPU and GPU temps as follows.

temps() {
    watch -d -n1 'sensors coretemp-isa-0000 nouveau-pci-0100'

This works great giving me this output.

Adapter: ISA adapter
Core 0:         +35.0c
Core 1:         +33.0c
Core 2:         +33.0c
Core 3:         +34.0c

Adapter: PCI adapter
GPU core:      +0.86 V
fan1:          780 RPM
Temp1:         +41.0c
Power1:        13.26 W 

I also have this function that monitors CPU MHz..

mhz() {
    watch -d -n1 'cat /proc/cpuinfo | grep "MHz"'

This also works great on its own giving me this output

cpu MHz        :1600.001
cpu MHz        :1600.001
cpu MHz        :1600.001
cpu MHz        :1600.001

But I want to be able to have one function that will give me both outputs together but I just cant get it to work.

I have tried a few things to combine these two functions into one in my .bashrc so I get one output with both temps and core clocks. but so far watch just gives me errors or a blank screen.

These are some of the things I have tried. (apologies for butchering these commands but i feel just trying on my own is a good way to learn but I've been unsuccessful so far.)

First thing i tried simply just to put them together.

watch -d -n1 'sensors coretemp-isa-0000 nouveau-pci-0100 cat /proc/cpuinfo | grep "MHz"'

This just gives me errors. I have tried many different ways of quoting things to try to get it to work (i know watch is very particular about quoting). When that failed i tried to create variables for the sensors and the cat command but i dont think this was helping me for example i had this..

temp="watch -d -n1 'sensors coretemp-isa-0000 nouveau-pci-0100'"
clock="watch -d -n1 'cat /proc/cpuinfo | grep "MHz"'"

watch -d -n1 $temp $clock

Again failure :(

If anyone can help me work out how to get the watch command to output both so i dont have to have two separate functions I just want to type "temps" into my SSH on my ipad and be able to see my servers temps and core clocks in one output from the watch command.

  • You should have a look at conky which allows you to watch CPU's (with graphs), temperatures, Process Names, RAM usage, Disk space, Network Speeds and many other things on one window you position and size to your preference on the desktop. – WinEunuuchs2Unix Dec 24 '16 at 17:23
  • I have used conky in the past but my current server doesnt have a desktop! Just server with no GUI. – Hayden Shore Dec 24 '16 at 17:27
  • I've edited your post to remove "Hi", "thanks" and other unecessary information. meta.stackexchange.com/questions/2950/… – cat Dec 24 '16 at 19:46

It is as simple as joining the two commands together with a ; inside the argument string for watch:

watch -d -n1 'sensors coretemp-isa-0000 nouveau-pci-0100 ; grep MHz /proc/cpuinfo'

Note also that I simplified your second command, as grep can read from files directly.


You can do it like that:

temp='sensors coretemp-isa-0000 nouveau-pci-0100;'
clock='cat /proc/cpuinfo | grep "MHz";'

watch -d -n1 $temp $clock

This way you get 3 things:

  1. by using ; at the end of the command assigned to the variable you separate different commands
  2. with that you can add more variables and assign more commands to them, then just add them to watch
  3. with ; at the end of every command you can reorder variables to change order of information you display

You can also make an array for storing commands and then pass whole array to the watch command but it won't necessarily make maintaining of the script much easier - adding new commands to array will require new line for every command if you want to keep it clean and readable - you just won't have to remember to add new variable to the watch command. Array would also make a difference for point 3 above - you would have to reorder array assignments to reorder displayed information.


Improving the cat /proc/cpuinfo | grep "MHz"; to grep MHz /proc/cpuinfo; is also good idea, as mentioned by Byte Commander.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.