schedule Archives - The Linux GURUS https://thelinuxgurus.com/tag/schedule/ Learn Linux & DevOPS from THE LINUX GURUS Fri, 04 Jun 2021 14:41:06 +0000 en-US hourly 1 https://i0.wp.com/thelinuxgurus.com/wp-content/uploads/2020/01/cropped-thelinuxgurus_transparent_name.png?fit=32%2C32&ssl=1 schedule Archives - The Linux GURUS https://thelinuxgurus.com/tag/schedule/ 32 32 148921671 How to Execute a Command or a Script on system Startup or Reboot https://thelinuxgurus.com/how-to-execute-a-command-or-a-script-on-system-startup-or-reboot/ https://thelinuxgurus.com/how-to-execute-a-command-or-a-script-on-system-startup-or-reboot/#respond Tue, 16 Feb 2021 16:42:49 +0000 https://thelinuxgurus.com/?p=1166 Being a Linux system admin or even a general Linux user, you might be required to run some commands or scripts at a regular interval...

The post How to Execute a Command or a Script on system Startup or Reboot appeared first on The Linux GURUS.

]]>
Being a Linux system admin or even a general Linux user, you might be required to run some commands or scripts at a regular interval or at a needed time. We use crontab to accomplish these tasks & we have already discussed Crontab in our tutorial. But how can we execute a command or script on system startup or after a reboot?

Well, there are two ways we can execute a command or script on system startup or after a reboot,

1- using ‘/etc/rc.local’ file

2- using Crontab

Recommended Read:  Beginner’s guide to Backup Postgres Database

Also Read: Scheduling CRON Jobs with Crontab for Beginners

Let’s discuss both these methods one by one.


1- Using ‘/etc/rc.local’ file

This is my go-to method when I need to execute a command or script on system startup. To execute a command on startup, open the file ‘/etc/rc.local’,

NOTE:- In the latest CentOS version, we might find this file in ‘/etc/rc.d/rc.local’.

$ sudo vi /etc/rc.local

& add it into the file with full command path, like,

/bin/date

Save file & exit. To get the full path of the command, you can run the ‘which’ command,

$ which date

Now the command will execute on each startup or after a reboot as well. To add a script to the file, first make sure that the script is executable,

$ chmod +x /home/linuxtechlab/test.sh

& then edit the rc.local file,

$ sudo vi /etc/rc.local

/bin/sh /home/linuxtechlab/test.sh

Save the file & exit, we are done. Now let’s see the second method as well.


2- Using Crontab

For this method, we only need to create a new crontab job in our system. So to create a new crontab job, run the following command,

$ crontab -e

Then add the following job to crontab,

@reboot (sleep 120; /bin/sh /home/linuxtechlab/test.sh)

So we added the job to run on every reboot with a sleep period of 120 seconds because we want our system to be fully up before our script is executed, otherwise, our script might fail to run. We now end this tutorial on how to execute command or script on system startup or after a reboot. Please do share any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post How to Execute a Command or a Script on system Startup or Reboot appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/how-to-execute-a-command-or-a-script-on-system-startup-or-reboot/feed/ 0 1166
How to Schedule a Shutdown in Linux using Crontab? https://thelinuxgurus.com/how-to-schedule-a-shutdown-in-linux-using-crontab/ https://thelinuxgurus.com/how-to-schedule-a-shutdown-in-linux-using-crontab/#respond Wed, 30 Dec 2020 16:11:09 +0000 https://thelinuxgurus.com/?p=1276 Introduction 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...

The post How to Schedule a Shutdown in Linux using Crontab? appeared first on The Linux GURUS.

]]>
Introduction

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

Schedule a Shutdown in Linux

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

Schedule a Shutdown in Linux

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:

Schedule a Shutdown in Linux

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

Schedule a Shutdown

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:

Schedule a Shutdown in Linux

The newly generated Crontab file is shown in the image below:

Schedule a Shutdown in Linux

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.

Schedule a Shutdown in Linux

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.

Schedule a Shutdown in Linux

Conclusion:

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.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post How to Schedule a Shutdown in Linux using Crontab? appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/how-to-schedule-a-shutdown-in-linux-using-crontab/feed/ 0 1276