The best way to describe Cron is to label it as a time-based job scheduler. It means that this service can be used in Linux to schedule all those tasks that are supposed to occur at a specific time, however, you do not want to perform these tasks manually. In today’s article, we will teach you the method to schedule a shutdown using Crontab in Linux Mint 20.
Recommended Read: Scheduling CRON Jobs with Crontab for Beginners
Also Read: Install Redis on CentOS / RHEL
Schedule a Shutdown in Linux Mint 20 using Crontab
For scheduling a shutdown using Crontab in Linux Mint 20, you need to perform the four simple steps listed below:
Step # 1: Start the Cron Service on your Linux Mint 20 System:
First, you will have to start the Cron service by running the following command:
$ sudo systemctl start cron
When you will start the Cron service, if no errors are produced and it is started smoothly, then no output will appear on your terminal.
Step # 2: Check the Status of the Cron Service on your Linux Mint 20 System:
After starting the Cron service on Linux Mint 20, we will have to verify it since this service runs in the background. We can do this by checking its status with the command shown below:
$ sudo systemctl status cron
Since we successfully managed to start the Cron service on our Linux Mint 20 system, therefore, its status appeared to be “active (running)” as highlighted in the following image:
Step # 3: Access the Crontab File on your Linux Mint20 System:
Whenever you want to perform any activity using Crontab, you have to mention the entry of this activity in your Crontab file. The Crontab file can be accessed with the command shown below:
$ crontab –e
In our case, we have not scheduled any Crontab job before because of which we did not have a Crontab file created in advance. It means that after running the above mentioned command, our new Crontab file will be created. You will be able to see various options on your terminal as a result of running this command. Out of all these options, the most suitable and easiest one is to open your newly created Crontab file with the nano editor. The option number that corresponds to this option is “1” so we will simply enter “1” in our terminal as shown in the following image:
The newly generated Crontab file is shown in the image below:
Step # 4: Add a New Crontab Job to your Crontab File for Scheduling a Shutdown on your Linux Mint 20 System:
Once our Crontab file has been created successfully, we will write a Crontab job in our Crontab file for scheduling a shutdown on our Linux Mint 20 system. For demonstrating to you this method, we have created a sample scenario. In this scenario, we will create a Crontab job to shut down our computer system at 3:15 p.m. every day from Monday to Friday and will add its entry to our Crontab file. The syntax of creating such a Crontab job is as follows:
15 15 * * 1-5 root shutdown –h now
Here, the first 15 represents minutes, the second 15 represents hours, and 1-5 represents the working days of the week. The two stars represent the day of the month and month respectively (you can also specify these entities as per your requirements). After creating this entry, you can press Ctrl+ X for saving your Crontab file and exiting from the nano editor.
Once you will do this, you will notice that your Linux Mint 20 system will automatically install the updated Crontab as shown in the image below since you have just made some changes to your Crontab file. It means that now, your computer system will automatically shut down at 3:15 p.m. every day from Monday to Friday.
With the method presented to you in this article, you can conveniently schedule a shutdown in Linux Mint 20 system. In this article, we only presented to you with one example scenario, however, you can conveniently play around with the different Crontab job parameters to schedule these jobs at any desired time as per your requirements.
For more Linux tutorials, please visit LinuxWays.