{"id":19973,"date":"2023-07-31T07:38:10","date_gmt":"2023-07-31T07:38:10","guid":{"rendered":"https:\/\/linuxways.net\/?p=19973"},"modified":"2023-07-31T07:38:10","modified_gmt":"2023-07-31T07:38:10","slug":"how-to-run-crontab-every-5-minutes","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/how-to-run-crontab-every-5-minutes\/","title":{"rendered":"How to Run Crontab Every 5 Minutes"},"content":{"rendered":"<p>With Linux Distributions, it gets really easy and simple to automate our tasks. We can also specify which tasks should be performed at a particular time. Crontab makes it possible for us. We can schedule different jobs and each job is known as a cron job.<\/p>\n<p>Efficient use of crontab requires us to understand its syntax of it, which consists of five distinguished fields which are: minute, hour, day of the month, month, and day of the week. Each field will be accepting specific values or will be using special characters. Asterisks and slashes are used for every interval.<\/p>\n<p>We should be careful while using crontab, because improper settings and configurations may lead us to unexpected behavior. We should make sure to monitor and test scheduled tasks to make sure the proper functioning of our automated processes.<\/p>\n<p>We can perform Crontab in every Linux Distribution. This article will depict how we can have a cron job in Debian 12.<\/p>\n<p>Let&#8217;s see the Syntax of Crontab.<\/p>\n<h2>MIN HOUR DAY-Of-MONTH MONTH DAY-OF-WEEK<\/h2>\n<p>We can schedule our jobs based on minutes, hours, any day of the month, or day of the week as well.<\/p>\n<p>To start Crontab, we have a command that we can use.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span>crontab <span class=\"re5\">-e<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"733\" height=\"553\" class=\"wp-image-19974\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-1.png 733w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-1-300x226.png 300w\" sizes=\"auto, (max-width: 733px) 100vw, 733px\" \/><\/p>\n<p>Here we need to select a file editor that we will be using for our cron jobs. We will go with 1 here. It will open the Nano editor for us.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"737\" height=\"553\" class=\"wp-image-19975\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-2.png 737w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-2-300x225.png 300w\" sizes=\"auto, (max-width: 737px) 100vw, 737px\" \/><\/p>\n<p>Now let\u2019s create a cron job here. In this job, we will list out the content of our Downloads directory on our terminal. <img loading=\"lazy\" decoding=\"async\" width=\"739\" height=\"586\" class=\"wp-image-19976\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-3.png 739w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-3-300x238.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-3-150x120.png 150w\" sizes=\"auto, (max-width: 739px) 100vw, 739px\" \/><\/p>\n<p>This line will create a file with the name file.txt in our download directory after every 5 minutes.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"731\" height=\"549\" class=\"wp-image-19977\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-4.png 731w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-4-300x225.png 300w\" sizes=\"auto, (max-width: 731px) 100vw, 731px\" \/> Here the command got executed, and let\u2019s see if we have our file created or not.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"887\" height=\"551\" class=\"wp-image-19978\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-5.png 887w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-5-300x186.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-5-768x477.png 768w\" sizes=\"auto, (max-width: 887px) 100vw, 887px\" \/><\/p>\n<p>Here, the file has been created successfully and it will keep on repeating until and unless we stop this. To stop this, we just need to go back to the file and remove the line.<\/p>\n<p>Let\u2019s have another example here. In this example, we will run a bash script that will create a file in our Documents directory. For that, we will add our cron job command one more time.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"549\" class=\"wp-image-19979\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-6.png 732w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-6-300x225.png 300w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/p>\n<p>Here we have our command,<\/p>\n<p>In our bash file, we have a command that will create a text file in our Documents directory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"729\" height=\"550\" class=\"wp-image-19980\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-7.png 729w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-7-300x226.png 300w\" sizes=\"auto, (max-width: 729px) 100vw, 729px\" \/><\/p>\n<p>After five minutes, our cron job will execute and our script will create a file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"882\" height=\"543\" class=\"wp-image-19981\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-8.png 882w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-8-300x185.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/07\/word-image-19973-8-768x473.png 768w\" sizes=\"auto, (max-width: 882px) 100vw, 882px\" \/><\/p>\n<p>Here as we can see, we have a file which means the script and Cron job have been created and executed successfully.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Because of Crontab, our automation process is more efficient and effective now. Not only that, now we can have multiple jobs scheduled once and each job will be executed on its scheduled time. We can perform and use Crontab in all Linux distributions.<\/p>\n<p>This article was all about Crontab in Debian 12. We can schedule our jobs in Debian 12 with Crontab on a minute basis, daily basis, or even on a monthly basis. But in this article, we only discussed how we can schedule our job for 5 minutes.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Crontab Job is a process that allows Linux users to automate different tasks. We can set a time as well for each job to execute as well.<\/p>","protected":false},"author":110,"featured_media":20001,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-19973","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/19973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=19973"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/19973\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/20001"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=19973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=19973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=19973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}