Scheduling a system shutdown at a specific time on Linux

August 26th 2013

Sometimes, when you're running a long task, you might need to schedule a shutdown of your machine for sometime in the future.

Thankfully, the 'shutdown' command has this built in.

In Linux, you can schedule your computer (or server) to shutdown (poweroff) at a specific time or a specific number of minutes in the future.

To schedule a shutdown at 11pm you can issue:

Text Snippet:
$ sudo shutdown -P 23:00

Likewise, if you want to shut your machine down in 2 hours time, you can issue:

Text Snippet:
$ sudo shutdown -P 120

Basically, the 120 above represents the number of minutes in 2 hours.

Now, running that command in your terminal will leave a process running, which we don't actually want. So if you add an ampersand (&) on the end, it'll send the command and run in the background.

The above commands would become:

Text Snippet:
$ sudo shutdown -P 23:00 &

Likewise, if you want to shut your machine down in 2 hours time, you can issue:

Text Snippet:
$ sudo shutdown -P 120 &

Easy to use, and VERY useful. Especially if you're doing something and need to schedule a shutdown.

Issuing the command will also send a message to any logged in users and let them know that the machine will shutdown. This way they know to log out before the system shuts down.

Jacqueline commented on Oct 21st 2013

Thanks for share this code.I have a turlboe with this snippet. I'm using the WP 3.4.I need count the depth of the pages' or count only the parent page inside About' like this example:About- Company Research Research Dossier-ContactIn this case the total is 3. It's possible?Thanks / I'm willing to pay for the code