📅  最后修改于: 2023-12-03 15:02:42.746000             🧑  作者: Mango
Shell scripting is a powerful way to automate tasks and perform operations in Linux. One such task is to shut down the system after a certain amount of time. In this guide, we will learn how to shutdown Linux after a specified time using the Shell-Bash script.
The sleep command pauses the execution of the script for a set amount of time. We can use this command to delay the shutdown process.
To shutdown Linux after a specified time, we can use the following command:
sleep 600 && sudo shutdown -h now
This script will wait for 600 seconds (10 minutes) and then initiate the shutdown process using the sudo shutdown -h now
command. You can change the time interval as per your requirement.
The at command schedules tasks to be executed at a given time. We can use this command to schedule the shutdown process.
To schedule Linux to shutdown at a specific time, we can use the following command:
echo "sudo shutdown -h now" | at 21:30
This script will schedule the shutdown process at 9:30 PM. You can replace the time with any time of your choice.
There are also external tools available that provide a graphical interface to set the shutdown time. One such tool is Shutdown Timer.
Shutdown Timer is a simple tool that allows you to set a time after which your Linux system will shut down. It provides a graphical interface to set the desired shutdown time and also allows you to cancel the shutdown process if required.
You can install Shutdown Timer on Ubuntu and Linux Mint using the following commands:
sudo add-apt-repository ppa:vikoadi/ppa
sudo apt update
sudo apt install shutdown-timer
Once installed, you can launch Shutdown Timer from the applications menu and set the desired shutdown time.
In this guide, we learned how to shutdown Linux after a specified time using different methods. We used the sleep command, at command, and an external tool shutdown timer to achieve this. By automating the shutdown process, we can save time and improve productivity.