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
atq commands. They can be installed like below. The
at package provides both at and atq commands.
Ubuntu, Debian, Mint, Kali
$ sudo apt install at
Fedora, CentOS, Red Hat
$ sudo yum install at
$ sudo dnf install at
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 12:43 at> reboot
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
$ atq 2 Tue Nov 15 20:00:00 2016 a root
Remove Pending Jobs
We can remove pending jobs with atrm command.
$ atrm 2
- 2 is the id of the pending job which can be found with atq command
Run After 5 Minutes
$ at now + 5 minutes
Run 6 A.M. Monday
$ at 6am
Run 01 A.M. July 21
$ at 1am Jul 21
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.
$ crontab -e
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
$ crontab -e -u ismail
Add Entry Cron Table
We will add a new entry to the cron table
0 20 * * * /sbin/shutdown
This will shut down our system every day at 20:00