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
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 :)
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 :)
In ubuntu Karmic I also had to set the XAUTHORITY var as well as the DISPLAY before it could “open” the display though ssh
In ubuntu Karmic I also had to set the XAUTHORITY var as well as the DISPLAY before it could “open” the display though ssh
@Daniel B: Thank you for this information, very helpful.
@Daniel B: Thank you for this information, very helpful.
@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.
@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.
I found this resolution to my problem.
sudo vbetool dpms off
Thanks
I found this resolution to my problem.
sudo vbetool dpms off
Thanks
thanks! i appreciate this very much. i didn’t know xset could do that!
thanks! i appreciate this very much. i didn’t know xset could do that!
Appreciate the post. Just looking to do the same thing after looking at how much my monitors cost me each month in electricity :-(
Great – glad to help!
sudo vbetool dpms off did the trick for me!
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?
My guess would be that it is something to do with how the iMac determines when it should turn on the backlight. There is this script from 2005 (http://hintsforums.macworld.com/archive/index.php/t-42776.html) that seems to work to disable the backlight, you might want to check that out. Looks like its a hack but should work for you.
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?
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?
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?
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?
Exactly what I needed. Keep it up!
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.