As previously written on this blog, I have set up a display in our lobby at work to display the day’s current events and meetings using Ubuntu and a tiny PC. Since this is a display which is on all day, the screensaver and monitor blanking (and other Energy Star features) are all turned off.

Under the auspice of wanting to save energy and also extending the life of a new monitor, someone suggested that we turn off the monitor at night using an electrical timer. A lightbulb went off in my head, that there must be a better way to do this via command line and then run it in the cron.

It turns out the solution is very simple. The xset command is the X server preferences command. It has a simple command to turn off the monitor:

$ xset dpms force off

and to turn the monitor back on:

$ xset dpms force on

You can also check the status of the X server settings by using:

$ xset -q

Also, when dpms turns off the monitor, it will turn back on after a keypress or by moving the mouse. Since this is a lobby display, there is no keyboard or mouse installed in the system.

I’ve rolled this into a little bash script with on, off, and status switches:

#!/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

You can then use cron to turn off the monitor at night, and back on in the morning:

0 20 0 0 0 /home/lobby/monitorControl.sh off
0 7 0 0 0 /home/lobby/monitorControl.sh on

This script will turn it off at 8pm and back on at 7am.

Note that this was written for an Ubuntu system, but the xset command is pretty generic so any system that runs Xserver like RedHat, CentOS, Debian, Fedora, etc should be able to use the script as well.

24 comments
  1. Pingback: Dave Drager
  2. I have 2,sometimes 3 computers in my bedroom,they make use of the “blank screen” in the screensaver settings.But the backlight is on despite the screensaver settings and produce a spooky glow when the time comes to meet the sandman.I tested your solution “xset dpms force off” and even the backlight disappeared,tonight and in the future i am going to sleep better…Thank you for a real lifesaver :)

  3. I have 2,sometimes 3 computers in my bedroom,they make use of the “blank screen” in the screensaver settings.But the backlight is on despite the screensaver settings and produce a spooky glow when the time comes to meet the sandman.I tested your solution “xset dpms force off” and even the backlight disappeared,tonight and in the future i am going to sleep better…Thank you for a real lifesaver :)

  4. In ubuntu Karmic I also had to set the XAUTHORITY var as well as the DISPLAY before it could “open” the display though ssh

  5. In ubuntu Karmic I also had to set the XAUTHORITY var as well as the DISPLAY before it could “open” the display though ssh

  6. @Daniel B: Pardon my ignorance, but how would I set the XAUTORITY var and DISPLAY? I’m getting “xset: unable to open display “” as well.

  7. @Daniel B: Pardon my ignorance, but how would I set the XAUTORITY var and DISPLAY? I’m getting “xset: unable to open display “” as well.

  8. Appreciate the post. Just looking to do the same thing after looking at how much my monitors cost me each month in electricity :-(

  9. On an iMac (Ubuntu 10.10) work fine, the display goes off and so does the backlight, but backlight turns on back again in about 10 seconds (though the screen remains black). Is it a graphics card (ATI Mobility Radeon HD 4670) or an Xserver problem?

  10. i get the following error when running the script

    Turning monitor on…No protocol specified
    xset: unable to open display “:0.0”
    done.
    Check:No protocol specified
    xset: unable to open display “:0.0”

    also i tried adding the command to a php script for use in a cron job. It work when i run manually, but the cron doesn’t seem to have any effect.

    any ideas?

  11. Are you logged in on command line under the same user as the display? When you open a command prompt when logged in, what does “echo $DISPLAY” show?

  12. echo $DISPLAY shows :0.0

    i also need to display to be off while the system is booting up and then turn on after boot is complete, is that possible?

  13. ok so it your script works for me when i use vbetool dpms off.

    but why wont it work when i call it from a cron job?

  14. i search the complete internet for an answer on this also, and finally found it.

    To keep others from searching for this, cron needs the full path to vbetool
    on ubuntu “/usr/sbin/vbetool dpms off” willl do the trick

Comments are closed.

You May Also Like

Network Solutions worldnic.com nameservers down

Network Solutions worldnic.com nameservers both appear down. Pings get through occasionally, this…

Operation Replace Cable Programming and HD DVR Box – Part 1 – The Plan

I’ve decided to replace my cable plan and DVR box with something…

Exporting Announcements from WHMCS

Doing some integration work with WHMCS, I found the need to export some of the announcements into Wordpress. Since there isn’t any native implementation of this, I found the best way is to export it directly from the database. The PHP code to do this is fairly easy…

A Poor Man’s VPN: Proxy Web Connection to Remote Server (via SSH and Tunnel)

Did you ever have a situation where you needed to access a…