Cron helps us to run tasks automatically in the background in defined intervals. Cron is e.g. used to automatically create backups every night to sync files e.g. once an hour or to start updates or download files at specific intervals. This tutorial will show you how to set up and edit cronjobs using the crontab command and the GUI tool Gnome Schedule.
Crontab command is used to list and edit cron jobs. For the usage of this command, we need to follow the following steps.
First of all, open Terminal by clicking on Ubuntu launcher and search for Terminal.
Now click on the Terminal and wait for the terminal to open.
Once the terminal is opened, you will have a screen like this:
In order to check which crontabs are running presently on our system, we will use the command “sudo crontab –l”.
Enter the required credentials.
As you can see we are having no crontabs for this directory because there has been no crontab created for this root user.
To open the crontab in our default editor we use the command, crontab-e.
Enter the required credentials.
If you are using crontab for the first time ever, then you are made to select one editor.
You may select any one of your desire. The tasks running in the background will appear.
If you are using it for the first time, then select the Nano editor. You’ll be able to find out the Nano text editor, that is identified by the “GNU nano” header located at the top of your window of the terminal. In case, if you don’t, crontab probably will be opened in the vi text editor.
And if you’re not much comfortable in using vi, you easily quit into vi. After pressing enter you will be able to close it.
We can use the arrow keys/ page down keys to scroll to the bottom of the crontab file in Nano. All of the lines that begin with # are “comment lines”. These comments are helpful for the people who are editing the files by providing essential information of their use.
Lines that are written in the crontab file are in the following sequence, they have following acceptable values:
1) minute (0-59)
2) hour (0-23)
3) day (1-31)
4) month (1-12)
5) weekday (0-6)
6) command
We have used * character to match any of the value. Now if we want to the command /usr/bin/example every day at a particular pre-defined time say 12:30 then this is what will we do. We will use 29 0 * * * /usr/bin/example. We have a zero here because an hour starts with a zero but day begins with a 1.
So, this is how we schedule a particular task.
We use ctrl+o in order to save the file in crontab in Nano.
Step 1:
For this, you simply go to the command line and type the following command.
sudo apt-get update && sudo apt-get install gnome-schedule
After that it will ask for the credentials once we enter them, the GNOME schedule will begin to install. This method is much easier since we just have to enter the required fields. So, once it is installed you may see how helpful it is for you to schedule the cronjobs using Gnome scheduling.
It will ask permission so press Y to continue.
Step 2:
After a while, the GNOME schedule has been installed. It will appear as scheduled tasks in the applications of the system.
Step 3:
On double-clicking, we will get a window that is “Configure Scheduled Tasks”.
Step 4:
We see the “New” field in the above screenshot. Click on it and then from the drop-down menu select Recurrent Task.
In the above window, we need to fill out all of the asked information which is mandatory to create a new job. This information is going to be:
On looking at this window’s bottom, a bottom saying “Add as Template” present. means we can add a job as a template. If this a job, then we surely can base other jobs on it. On creating the template jobs, we can eventually create numerous jobs based on that template. For this, we just need to click on “new- drop down” as we did previously and then we click selecting from the template.
If we want to create the cron jobs, sudo permissions are also needed to run. So, we open up a terminal window and then Issue the command sudo gnome-schedule. We then schedule the job as described above.
In this tutorial, we have discussed how to schedule tasks using crontab. The first part of the tutorial is based on the command line. Whereas, the second part shows how to maintain cronjobs using GNOME GUI.
Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…
ISPConfig is an open-source control panel that allows users to manage multiple servers from a…
As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…
Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…
Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…
phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…