{"id":6348,"date":"2023-12-06T10:42:00","date_gmt":"2023-12-06T10:42:00","guid":{"rendered":"https:\/\/www.smarthost.au\/blog\/?p=6348"},"modified":"2024-06-18T11:04:21","modified_gmt":"2024-06-18T11:04:21","slug":"creating-a-cron-job-in-the-task-scheduler","status":"publish","type":"post","link":"https:\/\/www.smarthost.au\/blog\/creating-a-cron-job-in-the-task-scheduler","title":{"rendered":"Creating a CRON Job in the Task Scheduler"},"content":{"rendered":"\n<p>CRON tasks are automated jobs scheduled to run in Unix-based operating systems. Cron is a program used for planning and executing specific tasks at defined intervals, such as every minute, every hour, daily, etc.<\/p>\n\n\n\n<p>You can set up a CRON job in cPanel under the Cron Jobs section.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"241\" src=\"https:\/\/www.smarthost.au\/blog\/wp-content\/uploads\/2024\/06\/Zrzut-ekranu-2023-12-6-o-11.33.35-1024x241-1.png\" alt=\"\" class=\"wp-image-6436\" srcset=\"https:\/\/www.smarthost.au\/blog\/wp-content\/uploads\/2024\/06\/Zrzut-ekranu-2023-12-6-o-11.33.35-1024x241-1.png 1024w, https:\/\/www.smarthost.au\/blog\/wp-content\/uploads\/2024\/06\/Zrzut-ekranu-2023-12-6-o-11.33.35-1024x241-1-300x71.png 300w, https:\/\/www.smarthost.au\/blog\/wp-content\/uploads\/2024\/06\/Zrzut-ekranu-2023-12-6-o-11.33.35-1024x241-1-768x181.png 768w, https:\/\/www.smarthost.au\/blog\/wp-content\/uploads\/2024\/06\/Zrzut-ekranu-2023-12-6-o-11.33.35-1024x241-1-520x122.png 520w, https:\/\/www.smarthost.au\/blog\/wp-content\/uploads\/2024\/06\/Zrzut-ekranu-2023-12-6-o-11.33.35-1024x241-1-740x174.png 740w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>There, you have the option to set the time for the task to run and specify the command.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"958\" src=\"https:\/\/www.smarthost.au\/blog\/wp-content\/uploads\/2024\/06\/Zrzut-ekranu-2023-12-6-o-11.35.52-1024x958-1.png\" alt=\"\" class=\"wp-image-6437\" srcset=\"https:\/\/www.smarthost.au\/blog\/wp-content\/uploads\/2024\/06\/Zrzut-ekranu-2023-12-6-o-11.35.52-1024x958-1.png 1024w, https:\/\/www.smarthost.au\/blog\/wp-content\/uploads\/2024\/06\/Zrzut-ekranu-2023-12-6-o-11.35.52-1024x958-1-300x281.png 300w, https:\/\/www.smarthost.au\/blog\/wp-content\/uploads\/2024\/06\/Zrzut-ekranu-2023-12-6-o-11.35.52-1024x958-1-768x719.png 768w, https:\/\/www.smarthost.au\/blog\/wp-content\/uploads\/2024\/06\/Zrzut-ekranu-2023-12-6-o-11.35.52-1024x958-1-520x486.png 520w, https:\/\/www.smarthost.au\/blog\/wp-content\/uploads\/2024\/06\/Zrzut-ekranu-2023-12-6-o-11.35.52-1024x958-1-740x692.png 740w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>To execute any file on the account through a CRON job, you can use one of two methods. You can execute a CRON job using a browser link to the file (Method 1) or by utilizing a selected PHP version along with the file path from the user account (Method 2).<\/p>\n\n\n\n<p><strong>Method 1:<\/strong><\/p>\n\n\n\n<p>To use a CRON job that triggers a script via a link, use the following command:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><code><strong>wget -q -O \/dev\/null [address] &gt; \/dev\/null 2&gt;&amp;1<\/strong><\/code><\/p>\n\n\n\n<p>The <code>-O<\/code> option allows specifying the path for writing (using <code>\/dev\/null<\/code> ensures the file is not saved). The <code>-q<\/code> option prevents logging the operation. <code>\/dev\/null 2&gt;&amp;1<\/code> redirects to the void, meaning no email notification will be sent about the CRON job execution. Replace [address] with the full link to the page to be called.<\/p>\n\n\n\n<p>For regularly executed tasks, it is recommended to use <code>&gt; \/dev\/null 2&gt;&amp;1<\/code> to avoid filling the disk space with notifications.<\/p>\n\n\n\n<p><strong>Method 2:<\/strong><\/p>\n\n\n\n<p>To execute a CRON command through PHP, use the following command:<\/p>\n\n\n\n<p><code><strong>\/opt\/cpanel\/ea-php74\/root\/usr\/bin\/php \/home\/username\/file_to_execute &gt; \/dev\/null 2&gt;&amp;1<\/strong><\/code><\/p>\n\n\n\n<p>In this case, provide the full path to the file and the PHP version to be used. In the example above, PHP version 7.4 is used.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CRON tasks are automated jobs scheduled to run in Unix-based operating systems. Cron is a program used for planning and executing specific tasks at defined intervals, such as every minute, every hour, daily, etc. You<a class=\"read-more\" href=\"https:\/\/www.smarthost.au\/blog\/creating-a-cron-job-in-the-task-scheduler\">Continue reading<\/a><\/p>\n","protected":false},"author":20,"featured_media":6349,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[437,1123],"tags":[318,1124,1125,1126],"class_list":["post-6348","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpanel-pl","category-cron","tag-cpanel-hr","tag-creating-a-cron-job-in-the-task-scheduler","tag-cron","tag-cron-jobs"],"_links":{"self":[{"href":"https:\/\/www.smarthost.au\/blog\/wp-json\/wp\/v2\/posts\/6348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.smarthost.au\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.smarthost.au\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.smarthost.au\/blog\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.smarthost.au\/blog\/wp-json\/wp\/v2\/comments?post=6348"}],"version-history":[{"count":2,"href":"https:\/\/www.smarthost.au\/blog\/wp-json\/wp\/v2\/posts\/6348\/revisions"}],"predecessor-version":[{"id":6438,"href":"https:\/\/www.smarthost.au\/blog\/wp-json\/wp\/v2\/posts\/6348\/revisions\/6438"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.smarthost.au\/blog\/wp-json\/wp\/v2\/media\/6349"}],"wp:attachment":[{"href":"https:\/\/www.smarthost.au\/blog\/wp-json\/wp\/v2\/media?parent=6348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.smarthost.au\/blog\/wp-json\/wp\/v2\/categories?post=6348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.smarthost.au\/blog\/wp-json\/wp\/v2\/tags?post=6348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}