{"id":326537,"date":"2021-08-17T15:00:44","date_gmt":"2021-08-17T12:00:44","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-launch-cron-automatically-in-wsl-on-windows-10-and-11\/"},"modified":"2021-08-17T15:00:44","modified_gmt":"2021-08-17T12:00:44","slug":"how-to-launch-cron-automatically-in-wsl-on-windows-10-and-11","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-launch-cron-automatically-in-wsl-on-windows-10-and-11\/","title":{"rendered":"#How to Launch Cron Automatically in WSL on Windows 10 and 11"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a286af3d1b1f\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a286af3d1b1f\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-launch-cron-automatically-in-wsl-on-windows-10-and-11\/#Cron_Isnt_Running_by_Default\" >Cron Isn\u2019t Running by Default<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-launch-cron-automatically-in-wsl-on-windows-10-and-11\/#Prepare_Linux\" >Prepare Linux<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-launch-cron-automatically-in-wsl-on-windows-10-and-11\/#Set_Up_Cron_in_the_Windows_Task_Scheduler\" >Set Up Cron in the Windows Task Scheduler<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Launch Cron Automatically in WSL on Windows 10 and 11&#8221;<\/strong><\/p>\n<div>\n<figure style=\"width: 1200px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage wp-image-746907 size-full\" srcset=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/08\/shutterstock_1161964939.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/08\/shutterstock_1161964939.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/08\/shutterstock_1161964939.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"A hand holding a stopwatch.\" width=\"1200\" height=\"675\" data-crediturl=\"https:\/\/www.shutterstock.com\/image-photo\/stopwatch-human-hand-timer-1161964939\" data-credittext=\"Billion Photos\/Shutterstock.com\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\"><span class=\"type:primaryImage imagecredit\"><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.shutterstock.com\/image-photo\/stopwatch-human-hand-timer-1161964939\">Billion Photos\/Shutterstock.com<\/a><\/span><\/figcaption><\/figure>\n<p>Windows has several ways to automate tasks. The most common tool is the Windows Task Scheduler, but if you\u2019re using the Windows Subsystem for Linux (WSL), there\u2019s also the cron daemon that runs tasks in the background for your WSL install.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Cron_Isnt_Running_by_Default\"><\/span>Cron Isn\u2019t Running by Default<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>On Windows 10 and Windows 11, cron comes included with Linux environments like Ubuntu. The trouble is that WSL doesn\u2019t start cron automatically, meaning that your automated tasks aren\u2019t getting executed by default.<\/p>\n<p>To fix this, you could start cron manually every time you open the command line, but manually starting a tool that\u2019s supposed to automate tasks is kind of missing\u00a0the point.<\/p>\n<p>Luckily, there\u2019s an easy way to fix this, and it requires using the Task Scheduler.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-746555\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/08\/CronNotRunning.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"A Windows WSL terminal window showing that cron is not running. \" width=\"650\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you\u2019ve never used cron in Linux to run tasks, check out our previous tutorial on how to schedule tasks on Linux. For our purposes here, we\u2019re going to assume that you\u2019ve already created some cron jobs in your WSL install and that you need help making sure that they run instead of babysitting cron all the time.<\/p>\n<p>For this tutorial, we\u2019re going to use <code>sudo service<\/code> to check and start cron, which is the recommended way to stop and start services on modern builds of Ubuntu\u2014the most popular distribution for WSL.<\/p>\n<p>Also, note that this tutorial assumes that you have administrator rights on your version of WSL. If you\u2019re the only user of your PC and you enabled WSL on your own, then you do have administrator rights.<\/p>\n<blockquote class=\"admonishment_tip\"><p><strong>Tip:<\/strong> This works in the Windows Subsystem for Linux on Windows 11, too\u2014not just on Windows 10.<\/p><\/blockquote>\n<p><strong>RELATED:<\/strong> <strong><em>How to Schedule Tasks on Linux: An Introduction to Crontab Files<\/em><\/strong><\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Prepare_Linux\"><\/span>Prepare Linux<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The first thing that we have to do is allow the computer to start cron without a password. When you start a service like cron, you use the command <code>sudo service cron start<\/code>. But that command requires a password, which Windows won\u2019t have access to when it starts up. The way around this is to turn off the requirement for a password for this command.<\/p>\n<p>To do that, open your WSL terminal window and type in <code>sudo visudo<\/code>.\u00a0Hit Enter on your keyboard, enter your Linux password, and hit the Enter key again. If you\u2019re using Ubuntu, this opens the \u201csudoers\u201d file using the beginner-friendly Nano command-line text editor. Sudoers is a file for system administrators that can change privileges and access rights for users.<\/p>\n<p>Add the following command to the bottom of the sudoers file, and then press Ctrl+o to save and Ctrl+x to exit the file.<\/p>\n<pre><code>%sudo ALL=NOPASSWD: \/usr\/sbin\/service cron start&#13;\n<\/code><\/pre>\n<p>This sudoers command says that any user who has enough privileges to use the sudo command (that should include you) doesn\u2019t require a password to run the command <code>sudo service cron start<\/code>, which starts the cron daemon.<\/p>\n<p>After you\u2019ve saved the file, you can check that the command is doing its job by typing <code>sudo service cron start<\/code>, and it should start cron without asking for a password. If that worked, let\u2019s turn cron off again so that we can test that the task we\u2019re creating in the next step works properly. To do that, please run <code>sudo service cron stop<\/code>.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Set_Up_Cron_in_the_Windows_Task_Scheduler\"><\/span>Set Up Cron in the Windows Task Scheduler<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>That\u2019s phase one of our journey toward cron automation. Let\u2019s move on to part 2 with the Task Scheduler. Tap the Windows key on the keyboard, and then search for \u201cTask Scheduler.\u201d Launch the \u201cTask Scheduler\u201d shortcut.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-746535\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/08\/TaskSchedulerSearchResults.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Search results in Windows 10 showing Task Scheduler as an option.\" width=\"650\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>When it starts up, look under the \u201cActions\u201d section and select \u201cCreate Basic Task.\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-746536\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/08\/TaskSchedulerCreateBasicTask.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Windows 10's Task Scheduler with a red arrow pointing to the &quot;Create Basic Task&quot; option.\" width=\"650\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This opens the Basic Task Wizard. First, it\u2019s going to ask you to name the task and give it a de<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">script<\/a>ion. You can enter whatever you want here. We called the task \u201ccron,\u201d and the description is, \u201cA task to start cron at system startup.\u201d Now, hit \u201cNext.\u201d<\/p>\n<p>In the following section, we get down to business. First, Windows wants to know when we want to run the task. Choose the \u201cWhen The Computer Starts\u201d radio button and click \u201cNext.\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-746537\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/08\/TaskSchedulerTrigger.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"A set of radio buttons in Windows 10 with a red arrow pointing to the &quot;When the computer starts&quot; option.\" width=\"650\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>In the next section, we want \u201cStart A Program.\u201d That option is selected by default, so click \u201cNext.\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-746538\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/08\/TaskSchedulerProgramAndOptions.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Windows 10 Task Scheduler's program options with red arrows pointing to the program path and the additional arguments text entry box.\" width=\"650\" height=\"450\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Now, we have to specify the program that we want to run, which is WSL. Enter the following into the \u201cProgram\/Script\u201d text entry box: <code>C:WindowsSystem32wsl.exe<\/code><\/p>\n<p>We also need to add some arguments, since all we\u2019ve done so far is start WSL, but inside WSL, we need to tell Ubuntu to start cron. So, in the \u201cAdd Arguments\u201d box, add: <code>sudo \/usr\/sbin\/service cron start<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-746544\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/08\/FinalTaskWizard.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Windows 10's Task Scheduler's final task creation window with a red arrow pointing to the option to open the task properties window at finish.\" width=\"650\" height=\"450\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Hit \u201cNext\u201d one more time, check the box that says \u201cOpen The Properties Dialog When I Click Finish,\u201d and then click \u201cFinish.\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-746579 size-full\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/08\/TaskPropertiesWindow-1.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"A Windows Task properties window with a red arrow pointing to the option &quot;Run whether user is logged on or not.&quot;\" width=\"650\" height=\"450\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The task is created, but we have to do one final thing to make sure that everything works. A new window will open, which shows the summary of the task that you created, but it\u2019s only set to run when you\u2019re logged on. We need to select the radio button that says \u201cRun Whether User Is Logged On Or Not,\u201d and then press \u201cOK.\u201d<\/p>\n<p>Now, let\u2019s test our task in two ways. First, in the main window of the Task Scheduler, scroll down until you see your task name. If you used the name \u201ccron,\u201d it should be found toward the top of the list.\u00a0Right-click the task and select \u201cRun.\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-746554\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/08\/CronIsRunning.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"A terminal window showing that cron is running.\" width=\"650\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Then, go back to your WSL terminal and type in <code>sudo service cron status<\/code>, and it should say that cron is running. If it isn\u2019t, double-check that you entered everything correctly in the previous steps.<\/p>\n<p>If everything worked properly in the first check, it\u2019s time for the big test. Restart your PC, and when you get back, open a WSL terminal and run <code>sudo service cron status<\/code>, which should report that cron is now running.<\/p>\n<p>Congratulations! You\u2019ve taken your first step into a larger, automated world. With cron running in the background, the cronjobs that you configure in WSL will automatically run on schedule.<\/p>\n<\/div>\n<p><script>\n setTimeout(function(){\n  !function(f,b,e,v,n,t,s)\n  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\n  n.callMethod.apply(n,arguments):n.queue.push(arguments)};\n  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';\n  n.queue=[];t=b.createElement(e);t.async=!0;\n  t.src=v;s=b.getElementsByTagName(e)[0];\n  s.parentNode.insertBefore(t,s) } (window, document,'script',\n  'https:\/\/connect.facebook.net\/en_US\/fbevents.js');\n   fbq('init', '335401813750447');\n   fbq('track', 'PageView');\n  },3000);\n<\/script><\/p>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.howtogeek.com\/746532\/how-to-launch-cron-automatically-in-wsl-on-windows-10-and-11\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Launch Cron Automatically in WSL on Windows 10 and 11&#8221; Billion Photos\/Shutterstock.com Windows has several ways to automate tasks. The most common tool is the Windows Task Scheduler, but if you\u2019re using the Windows Subsystem for Linux (WSL), there\u2019s also the cron daemon that runs tasks in the background for your WSL install&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":326538,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2021\/08\/shutterstock_1161964939.png?height=200p&trim=2,2,2,2","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-326537","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/326537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=326537"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/326537\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/326538"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=326537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=326537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=326537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}