Scheduling server shutdowns allows administrators to prepare their machines for any future planned maintenance, and potentially eliminates the need to manually run the shutdown commands at the required time frame.
If your server has not been rebooted for a long time (Linux: "uptime" command, Windows: Task manager, "Performance" tab), it is advisable to reboot your server one additional time before the actual maintenance. This is useful to prevent a long boot time after the maintenance itself, due to installation of updates or filesystem checks.
To schedule commands for a one-time execution at a particular time frame in the future, the "
at" command is widely used. This differs from using a cron job which is geared primarily towards commands which are required to be executed on a recurring basis.
This utility is not a standard system utility and must be installed separately on most distributions. This can be installed via your distributions package manager, the package name is typically named "
at". When this package is installed, a separate daemon "
atd" is also installed, which takes care of monitoring and executing the scheduled tasks.
To schedule a shutdown (or any other task), you just need to issue a single command. For example, schedule the shutdown to take place on 17 November 2014 at 16:00 local time on the server.
The scheduled command is given a job number, to which you can display all scheduled tasks via the "
atq" command. If you wish to cancel a scheduled task, issue the "
atrm" command with the job number as its parameter.
Scheduling a shutdown action on Windows system is a bit more complex. To achieve this, it is recommended to use of the built-in Task Scheduler.
- Open the Task Scheduler (Control Panel > Administrative Tools > Task Scheduler)
- From the Action menu, select "Create Basic Task..."
- In the "Create a Basic Task" window, give the task a name, for example, "Shutdown for Maintenance"
- Trigger: One time
- Start - Specify here the date and time local to the machine when the shutdown action should take place.
- Action: Start a Program
- Program/Script: Specify here the full path to the shutdown.exe file: C:\Windows\System32\shutdown.exe
- Add arguments: /s (this is the switch to specify that a shutdown action should take place)
- Verify on the Finish screen the details you have entered, especially the values in the Trigger and Action fields.
- The new task will appear in the Task Scheduler Library from where you can modify the task or remove it if necessary.
You can click on any of the keywords below this article to see all related articles for that keyword