Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to turn off monitor on a specific period of time automatically (for example between 07:00 and 11:00). Is there any command to be set in crontab file? Is there any better way?

In summary:

Turning off the monitor at 07:00 automatically.

Turning on the monitor at 11:00 automatically.

  • scren-saver & lock screen are disabled!
share|improve this question
Close-voter(s): The answer here is generally applicable to other people who want something similar--even if the OP never replied back this should still not be closed as not reproducible. (Also, the OP said it would take about one day to come back and check if the answer worked.) If there's some other reason to close this, I recommend commenting. – Eliah Kagan Sep 6 '13 at 3:09

Assuming that you are using the default gnome-screensaver for Ubuntu, open a terminal and run next commands followed by instructions:

  1. mkdir -p bin - this command will make a bin directory in your home folder if you don't already have it.
  2. gedit ~/bin/ - this will create the new file in gedit.
  3. Copy and paste the next script:

    export DISPLAY=:0 #very important if you want to be runned by a cron job
    current_hour=$(date +"%k")
    # Defining the disable_screensaver function
    function disable_screensaver {
        # Disabling sleep time
        # 0 value will never turn the screen off; you can change this value as you wish:
        # for example to turn the screen of after 10 min, use 600
        gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac 0
        gsettings set org.gnome.settings-daemon.plugins.power sleep-display-battery 0
        gsettings set org.gnome.desktop.session idle-delay 0
    # Defining the enable_screensaver function
    function enable_screensaver {
        # Enabling sleep time to 1 second
        gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac 1
        gsettings set org.gnome.settings-daemon.plugins.power sleep-display-battery 1
        gsettings set org.gnome.desktop.session idle-delay 1
        notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "Let's go to sleep now!"
    if [ "$current_hour" -ge "7" ] && [ "$current_hour" -lt "11" ]; then
    exit 0
  4. Save the file and close it.

  5. Go back into terminal and run: chmod +x - to grant execute access for the script.
  6. Just for test, to run your new script, type in terminal ~/bin/
  7. Edit the crontab entries using crontab -e command (by default this will edit the current logged-in users crontab) and add the following line:

    */1 * * * * /home/$USER/bin/  #change $USER with your username

    I have set the cron job for every minute, but you can change as you wish or as you think is better. See in this sense.

  8. Save the file and check the new crontab entry with crontab -l.

Now your screen will turn off every day between 7 and 11.

share|improve this answer
I've disabled gnome-screensaver and lock-screen, this is the reason that I want to turn off the monitor by command line automatically! Another note: The computer is at work, I'm on vacation now; however, I'll check your instruction tomorrow and put a feedback here :) – mini Jun 30 '13 at 17:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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