{"id":118,"date":"2021-09-17T06:51:34","date_gmt":"2021-09-17T06:51:34","guid":{"rendered":"http:\/\/webhostingpune.co.in\/blog\/?p=118"},"modified":"2021-09-17T06:51:36","modified_gmt":"2021-09-17T06:51:36","slug":"task-scheduling-in-linux-with-cron","status":"publish","type":"post","link":"https:\/\/webhostingpune.co.in\/blog\/task-scheduling-in-linux-with-cron\/","title":{"rendered":"Task Scheduling in Linux with cron"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Cron is a Linux and UNIX based tool that allows scheduling automated tasks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cron commands are stored in a file named for the user who created them in \/var\/spool\/cron\/<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">CRON Commands<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The Crontab command is used to create new cron files:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Crontab -l list the contents of your personal cron file.<\/li><li>Crontab -r removes all crontab entries.<\/li><li>Crontab -e opens your default text editor for cron job creation.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"395\" src=\"http:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron-1024x395.png\" alt=\"\" class=\"wp-image-119\" srcset=\"https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron-1024x395.png 1024w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron-300x116.png 300w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron-768x296.png 768w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron.png 1151w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>SYNTAX<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Steps Creating a Cron Job<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Login to your server as root<\/li><li>Create a directory for the purpose of testing as<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir \/crondemo<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Add files to the crondemo directory using touch command<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>touch file1 file2 file3 file4 file5<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Open crontab -e and add the command<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"401\" src=\"http:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron1-1024x401.png\" alt=\"\" class=\"wp-image-120\" srcset=\"https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron1-1024x401.png 1024w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron1-300x117.png 300w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron1-768x301.png 768w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron1.png 1121w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>SYNTAX 1<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Allow sometime and list the directory once the cronjob runs.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron2.png\" alt=\"\" class=\"wp-image-121\" width=\"668\" height=\"370\" srcset=\"https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron2.png 668w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2021\/09\/cron2-300x166.png 300w\" sizes=\"auto, (max-width: 668px) 100vw, 668px\" \/><figcaption>SYNTAX 2<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We hope you\u2019ve found this useful!\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cron is a Linux and UNIX based tool that allows scheduling automated tasks. Cron commands are stored in a file named for the user who created them in \/var\/spool\/cron\/ CRON Commands The Crontab command is used to create new cron files: Crontab -l list the contents of your personal cron file. Crontab -r removes all crontab entries. Crontab -e opens your default text editor for cron job creation. Steps Creating a Cron Job Login to your server as root Create a directory for the purpose of testing as Add files to the crondemo directory using touch command Open crontab -e and add the command Allow sometime and list the directory once the cronjob runs. We hope you\u2019ve found this useful!\u00a0<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-118","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts\/118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/comments?post=118"}],"version-history":[{"count":1,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts\/118\/revisions"}],"predecessor-version":[{"id":122,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts\/118\/revisions\/122"}],"wp:attachment":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/media?parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/categories?post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/tags?post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}