2

For a long a long time its been a problem for me (the human) to go to sleep early. A part of the problem is definitely that I often been to long by the computer at night I mess up my day rhythm and my life.

How can I solve this I would love to tell my computer to turn of at a certain time of the day? And give me a count down and be able to turn on again if I really need to turn it on afterwards and then be put to sleep again. Is there a thing like that?

I found this but I don't know how to implement it. I'm a bit noob at Linux.

muru
  • 197,895
  • 55
  • 485
  • 740
  • Yes, there are programs for that, but there is also scripting way. If this is a desktop with GUI, one can use dbus , and cron to schedue a shutdown. Would you be interested in something like this ? – Sergiy Kolodyazhnyy Feb 12 '16 at 04:29
  • 2
    This isn't a full solution, but take a look at this Q: http://askubuntu.com/questions/505929/shutdown-after-a-certain-time – Seth Feb 12 '16 at 05:11

2 Answers2

4

the easiest way would be through the command line:

try sudo shutdown -P 60 to shut down the machine in 60 minutes.

Alternatively you could set a time to shut down, using 24h format. For example sudo shutdown -P 1:00 will shut down the machine at 1:00 AM in the morning.

sudo shutdown -P now will shut down the CPU right away, e.g. now.

Hope that helps.

BenjB
  • 223
  • Thanks the sudo shutdown -P 1:00 did the trick.
    Is there a way that it can come on everyday automatically?
    – Martin Moltke Wozniak Feb 13 '16 at 22:07
  • You can most likely script it if you have some experience. Maybe this helps you: https://ubuntu.flowconsult.at/linux/ubuntu-15-04-startup-shutdown-script-systemd/ – BenjB Feb 13 '16 at 22:25
  • I tried to make the script.. but it failed. I get this message (maybe I should make a new thread?):

    (gedit:2971): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files

    – Martin Moltke Wozniak Feb 16 '16 at 14:17
  • Looks like an error with the dbus or the service. However I have to admit I lack the skills to help you there any further. It might be a good idea indeed to mark this question as answered and post the script one in a new question so it's easier to find. Remember to post your error as well. Should get an answer today. :-) – BenjB Feb 16 '16 at 14:47
2

This also works: with the -h option:

sudo shutdown -h 17:00 "Shutting down my Linux."

Here is the output:

Broadcast message from maestro@maestro-5567
    (/dev/pts/10) at 15:28 ...

The system is going down for halt in 92 minutes!
Shutting down my Linux. 
TheWanderer
  • 19,395
  • 12
  • 50
  • 65
JLM
  • 21