How to Determine if LCD Monitor is Turned on From Linux Command Line

前端 未结 8 971
南方客
南方客 2021-01-31 04:04

How do you tell if a computer\'s monitor(s) are turned on/off from the command line in Linux? I\'ve traditionally thought of monitors as output-only devices, but I\'ve noticed t

8条回答
  •  别跟我提以往
    2021-01-31 04:16

    From systembash.com, here is the code taken from the link, in case it will be down some day:

    #!/bin/bash
    export DISPLAY=:0.0
    
    if [ $# -eq 0 ]; then
      echo usage: $(basename $0) "on|off|status"
      exit 1
    fi
    
    if [ $1 = "off" ]; then
      echo -en "Turning monitor off..."
      xset dpms force off
      echo -en "done.\nCheck:"
      xset -q|grep "Monitor is"
    elif [ $1 = "on" ]; then
      echo -en "Turning monitor on..."
      xset dpms force on
      echo -en "done.\nCheck:"
      xset -q|grep "Monitor is"
    elif [ $1 = "status" ]; then
      xset -q|sed -ne 's/^[ ]*Monitor is //p'
    else 
      echo usage: $(basename $0) "on|off|status"
    fi
    

提交回复
热议问题