31

I use Torrents often, so I need to know how to make my computer start up and shut down automatically, Wi-Fi is switched on at six in the morning in my hotel and switched off at two AM. (I am able to schedule torrents, that's not a problem), I don't want my computer always plugged in to a power supply.

muru
  • 207,228
kernel_panic
  • 12,102

7 Answers7

21

For a one-time shutdown you can use

shutdown -h 02:00

To schedule it you can use cron. There are some GUIs for it like gnome-schedule.

But to start machine on schedule you have to look at BIOS/UEFI settings.

Update: check the answers about MythTV and Wake on Plan below to schedule startup.

int_ua
  • 8,892
15

Use a cronjob to auto sleep and auto resume. The command below will put the the computer to sleep at 02.00 AM and start the machine 4 hours later (14400 seconds)

00 2 * * * root /usr/sbin/rtcwake -m off -s 14400
Jom32y
  • 151
13

MythTV is able to shut down computer when it's no longer in use and wake it up a few minutes before the next recording starts. It does it by using ACPI functions to set wakeup time before shutting down. There is an extensive howto on configuring this, which basically boils down to:

First verify that your Linux kernel is 2.6.22 or newer and the HWclock update function has been disabled as described above.

Simple test to wake the machine 5 minutes from now

sudo sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm"
sudo sh -c "echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm"
cat /sys/class/rtc/rtc0/wakealarm

Check

cat /proc/driver/rtc

This should return a list of parameters. Check the "alrm_time" is 5 minutes into the future and the "alrm_date" is today.

Shutdown your computer and see if it comes back up in ~5 min.

sudo shutdown -h now  

(in Ubuntu 10.4 "sudo shutdown -P now" (-h may cause system to restart))

Of course, if you always need to shut the computer down at the same time and wake it up at the same time, you can just configure wake-up time in bios (if there's such an option) and schedule a shutdown right from init scripts

Sergey
  • 44,353
6

I've written an application to schedule startup, it's called Wake on Plan.

It's not available in the official repository yet (review pending) but you can start using it from PPA:

https://launchpad.net/~xintx-ua/+archive/wakeonplan

2014-2015 Update:

I've created the QML version with Ubuntu SDK using phone as a target and hoping for easy porting to desktop over a year ago. But click packages were never ready for use on desktop and now I'm waiting until snappy packages will be. Please notify me when they are. Right now even snappy list -uv crashed on my 15.04x64 installation and it doesn't look ready at all. Or you can try building a deb packages yourself, I'll try to help as much as I can.

int_ua
  • 8,892
1

I'm using an older Ubuntu 10.04.4 LTS system, and I have had some success with the rtcwake command. Use it like this on the command line:

# wake the system in 1 Hour:
sudo rtcwake -s 3600 -m disk

The -m disk option should put it in a low-power state, and depending on hardware support (i.e.: your own computer), you might even be able to successfully use -m off to fully power off.

Also, you can put the above into the /etc/crontab to schedule it automatically every day.

0

You can use shutdown command to schedule a shutdown. To shutdown at 2 AM you can use the following command:

sudo shutdown -h 2:00

You will need to run this command in terminal and leave the terminal open.

Regarding startup, I dont think that it is possible for Ubuntu or any app running on it to switch on a computer. You will need hardware assistance for this for example you can use Wake on Lan.

binW
  • 13,194
-1

I suggest this command in your cron:

dbus-send --system --print-reply --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

This does not need root.

Eric Carvalho
  • 55,453