GICT knowledge base
How to Schedule Shutdown and Reboot Commands in Linux
Published
Efficient power management is crucial for system administration, maintenance, and energy savings in any Linux environment. Whether you want to schedule a reboot after applying updates, automate nightly shutdowns of lab computers, or ensure a graceful server restart during off-peak hours, Linux provides versatile command-line tools to schedule shutdowns and reboots precisely when you need them.
This comprehensive guide walks you through the available commands and scheduling techniques, explores advanced automation, and shares best practices for safely managing power events on desktop, server, and cloud Linux systems.
Prerequisites
- Access to a Linux system (desktop, server, or virtual machine)
- Terminal access with sudo or root privileges
- Basic familiarity with command-line operations
- Understanding of your system’s scheduling needs and any policies regarding downtime
Introduction to Shutdown and Reboot Operations
Shutdown and reboot operations are essential parts of system maintenance. Reasons to schedule these tasks include:
- Applying updates or patches that require a reboot
- Performing hardware upgrades or replacements
- Saving energy by shutting down unused systems
- Restarting a system for troubleshooting or performance optimization
- Coordinating maintenance windows in enterprise environments
Linux offers several methods to schedule these events, including built-in commands and scheduling utilities.
The Shutdown Command
The shutdown command is the primary tool for safely shutting down or rebooting a Linux system. It gracefully notifies users, stops services, unmounts filesystems, and powers off or reboots the system.
Basic Syntax
$ sudo shutdown [OPTION] [TIME] [MESSAGE]
TIME: When to perform the shutdown (e.g., now, +10, 22:30)
MESSAGE: Optional message broadcasted to all users
Immediate Shutdown
To shut down the system immediately:
$ sudo shutdown now
Scheduled Shutdown
To shut down after a specific time interval (e.g., 15 minutes):
$ sudo shutdown +15
To shut down at an exact time (24-hour clock):
$ sudo shutdown 23:00
Adding a Message
Send a message to all logged-in users about the shutdown:
$ sudo shutdown +10 "System will shut down for maintenance in 10 minutes. Please save your work."
Reboot Instead of Power Off
To reboot instead of powering off, use the -r flag:
$ sudo shutdown -r now $ sudo shutdown -r +30 "System will reboot in 30 minutes for updates."
Power Off (Explicit)
To power off after shutdown (default on most systems):
$ sudo shutdown -P now
Canceling a Scheduled Shutdown or Reboot
If you need to cancel a previously scheduled shutdown or reboot before it happens:
$ sudo shutdown -c
You can optionally send a cancellation message:
$ sudo shutdown -c "Shutdown canceled. System will remain online."
Using the reboot, halt, and poweroff Commands
While shutdown is the most versatile, you can also use these commands for immediate actions:
- Reboot:
$ sudo reboot
- Halt (stop all CPUs):
$ sudo halt
- Power off:
$ sudo poweroff
Scheduling Shutdowns and Reboots with at and cron
For more complex scheduling, use the at and cron utilities.
Scheduling a One-Time Shutdown with at
The at command schedules jobs for a specific date and time.
Install the at package if missing:
$ sudo apt install at # Debian/Ubuntu $ sudo yum install at # CentOS/RHEL
Start and enable the atd daemon:
$ sudo systemctl enable --now atd
Schedule a shutdown:
$ echo "shutdown -h now" | at 01:30
This will power off the system at 1:30 a.m.
Schedule a reboot:
$ echo "shutdown -r now" | at 03:00
List Scheduled Jobs
$ atq
Remove a Scheduled Job
$ atrm <job_number>
Scheduling Regular Shutdowns/Reboots with cron
cron is used for recurring scheduled tasks.
Open the root user’s crontab:
$ sudo crontab -e
Add a line to schedule a daily shutdown at 11:00 p.m.:
0 23 * * * /sbin/shutdown -h now
Or to reboot every Sunday at 2:00 a.m.:
0 2 * * 0 /sbin/shutdown -r now
WARNING: Cron jobs must use absolute paths (e.g., /sbin/shutdown) and run as root to avoid permission issues.
Advanced: Scheduling with Systemd Timers
Many modern Linux distributions use systemd, which offers timers as a more flexible alternative to cron.
Creating a Systemd Timer for Shutdown
Create a service unit file, /etc/systemd/system/scheduled-shutdown.service:
[Unit] Description=Scheduled Shutdown [Service] Type=oneshot ExecStart=/sbin/shutdown -h now
Create a timer unit file, /etc/systemd/system/scheduled-shutdown.timer:
[Unit] Description=Run Scheduled Shutdown at 11:00 p.m. daily [Timer] OnCalendar=*-*-* 23:00:00 Persistent=true [Install] WantedBy=timers.target
Enable and start the timer:
$ sudo systemctl enable --now scheduled-shutdown.timer
Check the timer status:
$ systemctl list-timers
NOTE: Systemd timers offer precise scheduling, logging, and integration with other systemd units, making them suitable for advanced automation.
Practical Use Cases
- Schedule a Workstation to Shut Down After Hours:
$ sudo crontab -e # Add: 0 20 * * * /sbin/shutdown -h now
- Schedule a Reboot After Patching:
$ echo "shutdown -r now" | at 03:00
- Set Up a Weekly Reboot for a Server:
$ sudo crontab -e # Add: 0 4 * * 1 /sbin/shutdown -r now
(This example reboots every Monday at 4:00 a.m.)
- Notify Users Before Scheduled Events:
$ sudo shutdown -r +15 "System will reboot in 15 minutes for scheduled maintenance."
Monitoring and Troubleshooting
- Check Scheduled Jobs: Use atq for at jobs, crontab -l for cron, or systemctl list-timers for systemd timers.
- View Shutdown/Reboot Logs: Check /var/log/syslog, /var/log/messages, or use journalctl -b -1 for previous boot logs.
- Cancel Scheduled Actions: Use shutdown -c, atrm, or disable a specific cron/systemd job as needed.
Best Practices
- Plan Downtime: Schedule shutdowns and reboots during low-traffic periods or maintenance windows.
- Notify Users: Always warn users to prevent data loss and disruption.
- Automate with Care: Test scripts and scheduling commands in a safe environment before deploying in production.
- Document Schedules: Keep a record of all scheduled power events for audit and troubleshooting.
- Secure Access: Restrict shutdown/reboot permissions to trusted administrators only.
Conclusion
Scheduling shutdown and reboot commands in Linux is straightforward yet extremely powerful when leveraged with system tools like shutdown, at, cron, and systemd timers. By combining these native utilities, you can automate critical maintenance, optimize power usage, and maintain system reliability across desktops, servers, and virtualized environments. Always pair automation with user notifications, documentation, and careful planning to ensure a smooth and predictable experience for all system users.
[!NOTE] For more advanced scheduling needs or to integrate with third-party monitoring and orchestration tools, consult your distribution’s documentation and systemd manual pages for further options.
Related guides
How to Set Up zram on a Small VPS
Configure zram on Ubuntu with kernel and swap checks. Understand compressed memory limits, monitor real use and avoid unsafe swap-file changes.
LinuxHow to Find Services That Need a Restart After Updates with needrestart
Find services using outdated libraries with needrestart on Ubuntu. Read restart reports, review automatic restart policy and plan maintenance safely.
LinuxHow to Limit a Linux Service’s Memory with systemd
Limit a Linux service with systemd MemoryHigh, MemoryMax and swap controls. Check cgroup support, diagnose pressure and remove only your own policy.
LinuxHow to Protect SSH with CrowdSec on Ubuntu
Protect SSH with CrowdSec on Ubuntu. Connect log detection to firewall enforcement and test temporary blocking without losing administrator access.
