How To Shutdown Linux At Specified Time? – POFTUT

How To Shutdown Linux At Specified Time?

After installing updates it may need a reboot. Rebooting systems in office hours is a bad thing to happen. What can we do? We can set the Linux system to restart after office hours with an automated reboot. There are two ways to auto reboot. We will look at both of them.

Install at and atq

In this tutorial, we will use the at and atq commands. They can be installed like below. The  at package provides both at and atq commands.

Ubuntu, Debian, Mint, Kali

Install at and atq

Install at and atq

Fedora, CentOS, Red Hat

OR

Using At Command

We can use at command to specify boot time. We can do different things with at like sending emails etc. Now we want to restart 12:43

at provides shell to enter a command. To exit from the shell using CTRL+D .

  • 12:43 is the time we want to run the command
  • reboot is the command we want to run

List At Jobs

We may want to list already setup jobs with atq

Remove Pending Jobs

We can remove pending jobs with atrm command.

  • is the id of the pending job which can be found with atq command
LEARN MORE  How To Schedule Tasks From Command Line In Windows With Schtasks?

Run After 5 Minutes

Run 6 A.M. Monday

Run 01 A.M. July 21

Using Cron

cron is another service which can be used to schedule jobs, commands, and scripts. Running the given jobs periodically makes the cron different from the at . There is a table named crontab which stores the scheduled jobs and runs them accordingly.

Open Cron Table

To add a timed task we will open cron table to add an entry.

Open Cron Table With Specified User

By default, cron table is opened for current user so the added command will run for this user. We can specify a user to run the command like below

Add Entry Cron Table

We will add a new entry to the cron table

This will shut down our system every day at 20:00

Leave a Reply

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

Enjoy this blog? Please spread the word :)