Scheduling shutdowns


Scheduling shutdowns



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.


  Click here to expand...

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.

root@localhost:~# echo "shutdown -h now" | at 16:00 Nov 17 2014
warning: commands will be executed using /bin/sh
job 1 at Mon Nov 17 16:00:00 2014

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.


  Click here to expand...

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.

  1. Open the Task Scheduler (Control Panel > Administrative Tools > Task Scheduler)
  2. From the Action menu, select "Create Basic Task..."
    1. In the "Create a Basic Task" window, give the task a name, for example, "Shutdown for Maintenance"
    2. Trigger: One time
      • Start - Specify here the date and time local to the machine when the shutdown action should take place.
    3. 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)
    4. Verify on the Finish screen the details you have entered, especially the values in the Trigger and Action fields.
  3. 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