SSH – Detecting Monitors Over Local SSH Connection

monitorssshvideoxorgxrandr

I need to write a script to check on video related things on machines in the local network, e.g.

  • Is a monitor plugged in?
  • Are the video drivers up to date and appropriate for the hardware?
  • Is Xorg running?

However I am having trouble finding a reliable way of telling if a monitor is plugged in across a local ssh connection. For instance, if I ssh from machine A into another machine B that's on the same subnet, the xrandr tool returns information about the monitor plugged into machine A instead of machine B. I have tried a number of other tools, but all give the same effect. How can I be sure that I'm probing the monitor plugged to the machine that I'm connected to rather than the machine where I'm running the shell session?

Best Answer

Disable X11 forwarding (using -x switch to ssh) and set the DISPLAY environment variable for machine B. For example, this will tell you the settings for :0 on machine B:

ssh -x machineB
DISPLAY=:0 xrandr
Related Question