In this article, we will tell you the structure of Cron Jobs which is a very useful feature that is frequently used in the hosting sector. All other details such as usage structure, advanced examples and output results are still in the article. The examples we give expression during Hostgator which is built on shared hosting account cPanel control panel was carried out with.
Cron Job – What is a Scheduled Task?
The Linux operating system is a structure that is used in products such as Servers, Cloud Servers, Shared Hosting packages, VPS and Reseller packages and implements the task that you specify at the desired time and at any time you set. For example, you can perform operations such as backing up the database at X every day or sending an e-mail to one person, or running a script you set every 30 minutes with the Cron Jobs feature.
For advanced commands that require simple level script usage information for normal use, we will give some examples and detailed explanations about this feature, which requires the use of linux. Scheduled tasks play a crucial role in a healthy hosting. Even if you do not follow it, it’s really important that the backplane is the part that works for you and controls the systems.
Using Linux Web Hosting and Cron Jobs on Servers
The action to take to use scheduled tasks. The server or hosting package will be entered into the control panel and clicked on the Cron jobs logos. The following image shows a Cron Jobs logo on a standard cPanel.
A form different for each hosting company it will come prepared to enter the region after. Since the information requested on the form is the same, you can use the following information easily.
1) E-Mail: first in a valid e-mail address to inform you about the output of the Scheduled Tasks monitored. With this method, you can check your e-mail accounts without entering your control panel and check if your cron job is working and working properly.
2) Auto Setup: that the operation should be done when you can choose pre-created with these settings. It is the time interval that users use the most and you do not have to use this part. You can make a more detailed adjustment of the Time and Date settings manually.
3.) Minute: Minute setting of the specified task. In this section, the task can be done every X minutes or once a day, but in minutes. You will see more detail in the examples section.
4) The time at which the task every X hours or time settings should work is set here.
5.) Day: Day adjustment.
6) Month: Task in which month or months or condition or not to perform every month.
7.) Week Day – Weekday: You specify which day or days of work and will not work on all days of the week or the command. 0 = Sunday and 6 = Saturday. Only numbers are written, numbered 0-6.
All of the sections described above are the sections that concern the duty cycle and time. After this section, the area where the command to be requested to be counteracted is entered will appear. Commander or what tasks specified in this section as a command line only way to determine whether and how they should work. Tasks and the way it works is as follows.
It is almost impossible to describe these operations individually using Shell commands. The main set of commands used here on Linux is also working here. We will soon be talking about these and the most commonly used commands and logic for working with you. In other cases, teaching the commands one by one is no different than teaching C language from scratch. If there are other commands that you want to apply on the subject, you can request it from our comments section.
Scheduled tasks are automatically sent to your e-mail address when the task is run. If you do not want to get this information, you need to add the following code at the end of the commands.
> / dev / null
Examples of this will be explained shortly.
The structure of the commands is somewhat similar to the use of MS Friendly tags. With the corresponding command, many operations such as file execution, creation, invocation, sending can be performed. Below you can see a simple example code that provides database backup.
Mysqldump -u mysql_user -psifre database_ismi> backup.sql
Mysqldump is used with a standard backup command in the example above. Here, you can backup the database name password and user name part by changing their information. Let’s go to sample groups immediately.
Examples of Cron Job Time Adjustment
In the above section, we talked about the use of time. Now let’s make more examples of these.
Example 1: every day at 8:25 (AM) for performing the operation specified TA
25 8 * * * /home/users/test.sh
Time usage has a hierarchy from left to right as Minute -> Time -> Day -> Month -> Week Day. In the above explanation, there is sample code of the operation to be executed every month of the year, every day and every day at 8:25 o’clock. Month, Day, and Weekday sections are marked with “*” to cover the whole Moon, Days. At the end of the code, the command “/home/user/test.sh” is the command we want to run. We’ll just give you time examples here. Therefore, be sure to set the timing at the beginning rather than this command.
Example 2: Only Wednesdays 8:25 (AM) te code we want to run.
25 8 * * 3 /home/users/test.sh
As you can see, in this example, we write only part 3 which is Weekday, and only this process is done on Wednesdays.
Example 3: If we want the process to be performed at 8:00 AM and 16:00 PM every day time.
0 8,16 * * * /home/users/test.sh
Example 4: Transactions only if we want to be in on Mondays and 13:00 AM to 19:00 PM untill all the watches;
0 13-19 * * 1 /home/users/test.sh
This is done at the beginning of every hour of the time interval using the “-” sign.
Example 5: Each month, between 4 and 10 and let the process every 15 minutes.
* / 15 * 4-10 * * /home/users/test.sh
The “/” sign used in the above example is known as the repeat command. It was every 15 minutes because we used it under the minute portion. If we used / 2 under the hour part, the operation was done every 2 hours.
The time samples are understood according to our estimation. If you want to make different time samples about the topic, use our comments section for support.
Cron Jobs Command Examples
In this section, let’s look at examples that are added to the end of the time command and that are the actual command part. These are the most common and most commonly used processes. All of the examples below are set to work at 12:00 hours per day. You can adjust this setting according to your preference according to the above information.
1.) Database Backup:
0 12 * * * mysqldump -u VERITABILITY_USER -pSIFRE VERITABANI_ADI> backup.sql
Replace capital letters with your own database information. Do not touch places that are written in lower case.
2.) Database Backup (Without E-Mail):
0 12 * * * mysqldump -u VERITABILITY_USER -pSIGRE VERITABANI_ADI> backup.sql> / dev / null
We have included the above code in the last line. The now scheduled task finisher will not be notified by email.
3.) Database Restore:
0 12 * * * mysql -u VERITABANI_USER -pSIFRE VERITABANI_ADI <backup.sql
Here, mysql command is used to restore the backup.sql backup to the database. In the event of a malfunction, this can be quite useful. Of course, all updates made in the database will be back to their original state.
4.) PHP Code Execution:
0 12 * * * php /home/users/public_html/ozel_kod.php
In the above command, the php code will start with the first command “php” and the code will be in the specified time zone of your server by defining the location of your server “ozel_kod.php”.
5.) PERL Code Operation:
0 12 * * * perl /home/user/public_html/ozel_kod.pl
It works the same logic as PHP. Just start the code with perl and the extension ends in .pl.
6.) Making a query on a different website:
0 12 * * * / usr / bin / wget http://www.siteadi.com/ozel_kod.php
The command used to query a remote site “wget” command. Your hosting company will ask you if this code is set for you. Some companies can close this code at startup. The command line first specifies the extension of the wget function, followed immediately by the site and query extension to be used for the query. This query will occur at the specified time period and frequency.
7.) Find and delete files:
0 12 * * * find / onblock -type f -empty -delete
Find and un-delete commands are used above. You can use this command if you want to delete newly created files in your server or emptied some tmp folders at specified times. You can find files / folders that you want to find and delete the “/ oncache” folder name instead.
8.) Delete Files (if available):
0 12 * * * rm -rf directory
Above, rm is the command to delete a file that runs on linux. If the directory specified by -rf setting exists, deletion is performed. You can put the directory that will be deleted if you check the directory above and if it exists.
9.) File Creation and Authorization:
0 12 * * * mkdir -ma = rwx / home / new_directory
Above, we see a command that creates a new folder at the specified times and gives permissions to this folder CHMOD. The folder a = rwx specifies that the folder will be created in a location that is allowed to Read, Write, and Run Commands. R = Read, w = Write, x = Execute. You can change the CHMOD settings by removing the letters there.
10.) Update Awstats statistics:
0 12 * * * / user / stats /awstats.pl -config = AWStats. SiteName .com.conf -update
The above command is used to update the Awstats statistics in the specified periods. Update the locations we highlighted in bold with your own hosting and server information.
We gave many important and frequently used examples above. Apart from these, there are thousands of different codes and commands. What you do not know and wonder Hosting Directory as we will answer in the comments section below.
Frequently Asked Questions About Cron Jobs
Why Should I Use Cron Jobs? There is absolutely no obligation to do this once. It is a structure that provides great advantages to its users when used and helps to save web sites in adverse situations. Even if you do not look at your server for a long time, it creates and deletes the files that make up the server in your name. Your name tells you the status of other web sites and emails you. For this reason, we find it useful.
Does Plesk Panel Support Cron Jobs? First of all, all servers with a Linux operating system support these commands. There are different forms in Windows operating systems. If your Plesk you can enter commands on your dashboard section under the Task Scheduler is installed on Linux.
Why do not my scheduled tasks in my server and shared hosting work? Some hosting companies turn off the use of Cron Jobs during the initial opening phase. If these tasks are not working on your server or in your host package, ask your customer support staff to open them up. Firms will not respond to this, but if not, we suggest you change your host provider.
How Can I View Cron Jobs Logs? Go to your server’s file management section. ETC folder or the Var / log folder. You can view the history of processes executed and executed by cron jobs in the sys or rsyslog files in these folders. These folders may differ according to the hosting companies.But the first thing you need to do is log and etc folders.
We shared a detailed and comprehensive article on the subject with you. Please use the following section for any questions, comments and suggestions.0