How To Shutdown Linux At Specified Time?
After installing updates it may needed reboot. Rebooting systems in office hours is a bad thing to happen. What can we do? We can set Linux system to restart after office hours with automated reboot. There are two ways to auto reboot. We will look both of them.
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
1 2 | $ at 12:43 at> reboot |
at provides shell to enter command. To exit from shell use CTRL+D .
- 12:43 is the time we want to run command
- reboot is the command we want to run
List At Jobs
We may want to list allready setup jobs with atq
1 2 | $ atq 2 Tue Nov 15 20:00:00 2016 a root |
Remove Pending Jobs
We can remove pending jobs with atrm command.
1 | $ atrm 2 |
- 2 is the id of the pending job which can be find with atq command
Run After 5 Minutes
1 | $ at now + 5 minutes |
Run 6 A.M. Monday
1 | $ at 6am |
Run 01 A.M. July 21
1 | $ at 1am Jul 21 |
Using Cron
Cron is a service to run commands scripts at specified time.
Open Cron Table
To add timed task we will open cron table to add entry.
1 | crontab -e |
Open Cron Table With Specified User
By default cron table is opened for current user so added command will run for this user. We can specify user to run command like below
1 | crontab -e -u ismail |
Add Entry Cron Table
We will add new entry to the cron table
1 | 20 * * * /sbin/shutdown |
This will shutdown our system every day at 20:00