Howto Get Enough Sleep Despite StumbleUpon with Ubuntu

What?

I am a long-term StumbleUpon user, which means that I don’t get much sleep. Now, after almost 4 years of stumbling, I have decided to get my life back. Well, at least some sleep!

What does this do?

Every night when I have to work on the next day (Sunday night to Thursday night ), at 23:25 my computer shows me this little warning message:

go to bed warning

After the 5 minutes have passed, the computer shuts itself automatically down.

I use this little trick with Ubuntu, but it should work anywhere where Gnome is installed.

How?

Thanks to the power of Linux, this is not difficult to do for yourself, and configure it however you want it to behave:

  1. Open /etc/crontab with your favourite text editor (no need for crontab -e since this is the system wide crontab), e.g.
    sudo gedit /etc/crontab
  2. Add the following lines (replace manker with your username!)
    25 23 * * 0-4   manker  /usr/bin/zenity --display :0 --warning --text="Shutdown in 5 minutes. Go to bed."
    25 23 * * 0-4   root    shutdown -h +5
  3. The first part of both lines 25 23 * * 0-4 means that the commands are executed at 23:25, but only Sunday (day 0) to Thursday (day 4). Read man 5 crontab for a detailed description of that format.
  4. The first command uses zenity to show a warning message. You have to execute this as the same user that you use for working, or you will not see the message, so change manker to your username (root does not work either).
  5. The second command shutdown -h +5 means that the computer will halt in 5 minutes. This has to be run as root, and it also shows nice warning messages in all your open terminals so you can’t really miss it.
  6. Save the file, and stumble until it is 23:25.

Sweet dreams!

Related posts

  1. Howto Change Ubuntu Forced fsck
  2. How to Install Anything in Ubuntu Condensed
  3. Get More Space Out of Your ext3 Partition
  4. Clearlooks Compact Gnome Theme
  5. HOWTO Create MANIFEST.MF Classpath From Ant

73 thoughts on “Howto Get Enough Sleep Despite StumbleUpon with Ubuntu

  1. This is very useful, but usually I stumble before I work, so when I start working at about 1 o’clock in the morning I’d hate to have this bothering me.

  2. Great idea! I can’t begin to imagine how many hours I’ve lost to StumbleUpon. The worst is when you’re stumbling and you know you should stop.. but you just… can’t.. make.. yourself.. stop!

  3. This meeting of Stumbleoholics Anonymous is hereby adjourned.

    @K: You can change some of the numbers around. Just be careful what you’re changing…

  4. ! Ha! Great idea, I was addicted to StumbleUpon for about one year, than I got out of it after moving to Ubuntu, where I managed to resist installing SU toolbar for some weeks and after that I try to keep the usage of it low. It can eat all your time :) PS: Ofcourse I came here through Stumble Upon!

  5. @Tucks: thanks for the link, but I would not use user specific crontab for this, because shutdown only works as root, so you need to edit root’s crontab for shutdown, and your user one’s for the info window. Better use /etc/crontab directly.

  6. That seems like a great idea … their is a challenge tho … what do you do when you run a .com from home, and your computer is the server?

    I guess I could tell it to run /etc/init.d/kdm restart in 5 min instead of shutdown.

    Good idea though.

  7. You don’t really need gnome for this to work…

    Just make sure you have Zenity installed, and substitute gedit with any other editor, such as Nano or in my case Vim.

    Otherwise, smart use of crontab, it’s just not really stumble specific. Now if you had made a script that would only click the stumble button 3-4 times an hour… I’d take it.

  8. 5 minutes?

    From ‘man shutdown’:
    -c Cancels a running shutdown. TIME is not specified with this option, the first argument is MESSAGE.

    I’m an enabler. :P

  9. Thanks for the idea.
    I took away the shutdown feature and left only the reminder. I changed the text within the “quotes” to make it more of a friendly reminder than a warning.

    Tip: type “zenity –help” in terminal to get a list of other window types to display for instance “–notification”.

    What would be cool is if someone wrote a –question script that asked “are you working or playing?” -If you say working it does nothing. If you say playing it kindly helps you stop by shutting the system down.

  10. you should try making also another script to prevent you from restarting the PC after 10 minutes because you’ll probably won’t resist and start stumbling again. it should be a script that checks the system’s time and if it’s between 23:25 and 03:00 then it should shutdown again in 1 minute.

  11. omg. there are others like me?!?!?!?!!?

    staying up until the wee hours of the morning, continuously hitting the “Stumble!” button. over. and over. and over. and over. AND IT’S ALWAYS SOMETHING DIFFERENT!! gawd. i have even replaced my regular TV shows with “StumbleVideo”

    we are entering a new age.

    my name is Pollux…and i have a problem. \^.^/

  12. You can do this with Windows, too:

    Use scheduled tasks in the control panel to have it run “Shutdown.exe -s -t (seconds) -c “Time to get some sleep!”" every night at whatever time you want. :)

  13. This is great, this is my 3rd night on Stumble Upon, and found myself up until 5AM the first night, so I certainly see where this would come in handy. I will be using this! Thank you for sharing! Love Ubuntu and Beryl too!! Hasn’t ceased to amaze be yet.

    Mike

  14. it was really funny that i stumble this site with my ubuntu (gutsy) box. haha first, i thought it’s a trick that webpage analyzing my system :) i’ll give a try

  15. Nice hack, but I think I’d end up turning it off after it warned me. xD I’d have to make it do a random time between 11pm and 12am and give no warning, and hopefully I’d forget about it. (Maybe random days as well?)

  16. Good idea. I’d need an override though, like any good addict, I just want to stumble one more time. I can quit any time I want!

    I have it both ways, my pc laptop is windows with su and my home pc is ubuntu with su. When I’m compiling or copying something big with one pc, I can stumble with the other. Its awesome to have them both going at the same time. I actually use this method to quit for the night…

    When I see a site I’ve already seen today, I call it a night. – Ah hell, just one more.

  17. Hi Martin,

    Well this is nice trick ! However, for me it probably would not work, because then I start thinking: Is it really necessary to turn off my box just for 6 or 7 hours :-) Cool down all hardware and then heat it up again after couple hours can be costly. The hardware will suffer and I will need to replace it !!!:-) Moreover I’m not using MS Windows so I really do not need to restart !! :-)

    I think I will need to go for modified version similar to your but different :

    for f in $(seq 1 25200); do sleep 1; echo $f; done | zenity –progress –width 530 –pulsate –text ‘Leave Me Alone and go sleep ! See you in 7 hours. — Regards your PC’ –title ‘Sleeping and therefore I am not Listening to any IRQ calls’

    So tell me which version is better for Linux users ? Yours or mine?

    lubo

  18. Great to learn about crontab syntax. But what is this ever going talk about stumbling depriving people from sleep? I’m getting same pages from stuble quite often and sometimes it says I’ve seen all from some category. I’s also less time consuming to get links from stumbler than anywhere else.

  19. Wow. That’s neat.

    That’ll work on ANY Linux distro! Try it! :)

    (Christ. This “lol ubuntu” stuff is driving me nuts. Cause… y’know, the linux kernel is the linux kernel no matter WHAT you have on top of it.)

  20. Please for god’s sake use “crontab -e” to edit the file.
    If needed, you can export EDITOR=’nano’ if you can’t handle vim

  21. Daenyth, “crontab -e” is only required when you edit the user’s crontab so that they are installed. When modifying /etc/crontab you dont need to run this, see the header information of /etc/crontab.

  22. I really like this idea. I could really do with an application like that. I spend far too much time on my computer.

    Would this work on Mac OS X, asumming that the OS is similar?

  23. This is exactly what I need!

    One small problem: it doesn’t all work.

    It does shutdown, but I get no warning, so have been caught out when I was not aware of the time & had not saved everything before hand.

    Tonight I have written scripts to get zenity to work; I hope they will!

  24. I get no message via zenity to warn of the time & shutdown. When launched from the command line / script it works fine, but not from within crontab.

    What else is running has no effect.

    Any ideas would be welcome. Scripts are OK when they work, but I get frustrated when something like this beats me!

  25. … and even the scripts will not work.
    I have a script that makes a sound, and uses zenity to produce a pop-up.

    The sound plays, but the pop-up will not appear.

    -> at least I know the script is being called, but it is useless when I have the sound turned off (most of the time)

  26. Hi ian, the only thing I can think off is that you have to use the same username in the crontab that is currently using the desktop. also make sure that you are editing /etc/crontab and are not using “crontab -e”, this file has a different syntax.

    You can also try kdialog instead of zenity:

    kdialog --sorry "shutting down in 5 minutes"
  27. I have the same problem as Ian. Shutdown works a treat, but without the warning popping up.
    Can it possibly be something to do with rights? That I shuld do some chmod action? Can somebody enlight me, please?

  28. Maybe the “I ain’t got no warning” people don’t have zenity;
    for Ubuntu and other Debians, you may need to:
    sudo apt-get zenity

    From a shell or the run dialog, try;
    zenity –display :0 –warning –text=”Is this thing on?”
    or (definitely from a shell);
    which zenity
    to test whether you have it.

    But who shuts their machine off? BOINC has got work to do.

  29. FYI for anyone on Ubuntu not getting warnings. Try the command “xhost +” I couldn’t get warnings until I found the solution on this website. This disables access control (might be a bad thing).

    http://preview.tinyurl.com/6q4n6l

    I now have warnings. Not sure if this opens a security hole on my system though. Time to go RTFM.

  30. Oh THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU!!!!!!!!

    I’ve had the BEST sleep last night in bloody AGES!!

    THANK YOU *SO MUCH*!!!!!

    lol

  31. Pingback: StumbleUpon. 1. pomoc dla uzale?nionych ;) | OpenQbeu :]

  32. Pingback: Martin Ankerl » Blog Archive » Top 10 Posts of 2008

  33. how about the atd.
    its not always sure you want to shut down your whole pc in 5 minutes every day at a specific time.

    type something like that:

    sudo at now + 1 hour
    xmessage go to bed already
    shutdown -h +5

  34. Pingback: ?????? ?? ???? ???? « Linux

  35. Pingback: polaris14551 | ?? » ?Ubuntu??

  36. The --display parameter needs to be on the same display as X is currently running, which is stored in the $DISPLAY environment variable. Unfortunately this variable is not set when running from crontab, so I have just hardcoded :0. To find out where your X is running, type echo $DISPLAY and then add this output to the crontab.

  37. I love this, I am also a Ubuntu users. It is 10.30AM right now here in Las Vegas, Nevada and I have been stumbling from 5.30AM. I Stumbled to this site. I guess that is a hint that I need to put some kind of timer on my stumbling.

  38. Many people here say they found this article through StumbleUpon. I’m the opposite. I’m now installing StumbleUpon because I read this article.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>