{"id":34,"date":"2024-09-11T09:33:29","date_gmt":"2024-09-11T14:33:29","guid":{"rendered":"https:\/\/danielbondurantcybersecurityportfolio.online\/?p=34"},"modified":"2024-11-07T10:07:22","modified_gmt":"2024-11-07T16:07:22","slug":"cron-scheduling","status":"publish","type":"post","link":"https:\/\/danielbondurantcybersecurityportfolio.online\/?p=34","title":{"rendered":"Cron Scheduling"},"content":{"rendered":"\n<p>This post will demonstrate how to use Cron to set up a daily schedule for receiving the weather forecast email.<\/p>\n\n\n\n<p>The first step will be to go to crontab.guru to check the format. I want to have this email set to go out every day at 8 AM. The Cron format will be: 0 8 * * *<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXd5Uwy1jTq4hB-vjvkjxRv_T-G9dBHOEIXf7MEby56LXU3iChXo2_TwtwgIPV5FtUDAmJu6vvipcJvWZbqy8xjkLzREA8KaKvfsN7Ah2CngJEB_ZbBINexzkVMc7jZx3gw3Xxv4-j7cHFiWjZjxspuligKG?key=vW6ws-W07_b2TH9zWBO71g\" width=\"624\" height=\"607\"><\/p>\n\n\n\n<p>Now we go back to the CLI to access Cron with crontab -e<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"268\" height=\"61\" src=\"https:\/\/danielbondurantcybersecurityportfolio.online\/wp-content\/uploads\/2024\/09\/image-4.png\" alt=\"\" class=\"wp-image-74\" style=\"width:369px;height:auto\"\/><\/figure>\n\n\n\n<p>To set up the Cron job, we need to make a new line at the bottom that includes:<br> &#8211; The time format <code>(0 8 * * *)<\/code><br> &#8211; A pointer to the Python interpreter<code> (\/usr\/bin\/python3)<\/code><br> &#8211; The pathway to our script file <code>(\/home\/kali\/weather_email\/daily_weather.py)<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"562\" height=\"480\" src=\"https:\/\/danielbondurantcybersecurityportfolio.online\/wp-content\/uploads\/2024\/09\/image-6.png\" alt=\"\" class=\"wp-image-77\" style=\"width:622px;height:auto\" srcset=\"https:\/\/danielbondurantcybersecurityportfolio.online\/wp-content\/uploads\/2024\/09\/image-6.png 562w, https:\/\/danielbondurantcybersecurityportfolio.online\/wp-content\/uploads\/2024\/09\/image-6-300x256.png 300w\" sizes=\"auto, (max-width: 562px) 100vw, 562px\" \/><\/figure>\n\n\n\n<p>To test the job, I will set the Cron time to be 1 minute beyond whatever the current time is at the moment. For example, if the time is 11 AM, I will use 01 11 * * * for the job to run at 1101 AM.<\/p>\n\n\n\n<p>If everything is set up correctly, I will receive an email on the account I specified in the code&#8230;<br>And, no email.<\/p>\n\n\n\n<p>In the process of trying to figure out why the job was not running, I decided to add a line to the job that will write a log file with errors:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt; \/home\/kali\/weather_email\/cron.log 2&gt;&amp;1<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"922\" height=\"56\" src=\"https:\/\/danielbondurantcybersecurityportfolio.online\/wp-content\/uploads\/2024\/09\/image-5.png\" alt=\"\" class=\"wp-image-75\" style=\"width:692px;height:auto\" srcset=\"https:\/\/danielbondurantcybersecurityportfolio.online\/wp-content\/uploads\/2024\/09\/image-5.png 922w, https:\/\/danielbondurantcybersecurityportfolio.online\/wp-content\/uploads\/2024\/09\/image-5-300x18.png 300w, https:\/\/danielbondurantcybersecurityportfolio.online\/wp-content\/uploads\/2024\/09\/image-5-768x47.png 768w\" sizes=\"auto, (max-width: 922px) 100vw, 922px\" \/><\/figure>\n\n\n\n<p>After the job attempted to run again, I get this error report:<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXcblAFhDgs0hIaCzPiTup2miv5IouPeMnH9hVBgYHdFk2T70p5VXEzM1LMnimegljZhotX-0IclQJAk8REn-qXqzTv-mdtSoexkq3pGdLbLSJ8dBewNyLD0nHZZHVgBjM6qWZwnN4G5UaEDNBOJiRfIovY?key=vW6ws-W07_b2TH9zWBO71g\" width=\"624\" height=\"116\"><\/p>\n\n\n\n<p>Looking into this error I realized that Cron needs a direct file path to the <code>weather_template.html<\/code> file. Otherwise, it doesn&#8217;t know where to find the file. To fix this, we need to go back into the script and add the full pathway to the file.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXeClM6CfVPcwkygPl23KL0u5qFs1EBALwjIhBo6ZPZ9ODklo-Ko_uspHMQCW_Uegh6V_yJXSkHz2YLB_prhAxLoyTxswlE_ct2CPYa6NdpQ4bQgPs_fHOYOotLrFLu4Cu7As3gXTdq1-EqpGWFyzPy41rI?key=vW6ws-W07_b2TH9zWBO71g\" width=\"547\" height=\"43\"><\/p>\n\n\n\n<p>Now the Cron job can run, and the email is received.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXfkxGi60DLQjEm0MVMH4DbefVjyTNvim9Kk_2HczFb6__s4AJe2_BGrowwQ204b77uiNfOoaHzgD1Zj8IqwvQbOaShB8E5AmvpVlMPe8F_w849CJ-UT-I0YvraqCcYqQdquo4wAQB-jyZPnvfhYag4-4b53?key=vW6ws-W07_b2TH9zWBO71g\" width=\"505\" height=\"389\"><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post will demonstrate how to use Cron to set up a daily schedule for receiving the weather forecast email. The first step will be to go to crontab.guru to check the format. I want to have this email set to go out every day at 8 AM. The Cron format will be: 0 8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,6],"tags":[],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-cron","category-linux"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/danielbondurantcybersecurityportfolio.online\/index.php?rest_route=\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/danielbondurantcybersecurityportfolio.online\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/danielbondurantcybersecurityportfolio.online\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/danielbondurantcybersecurityportfolio.online\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/danielbondurantcybersecurityportfolio.online\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=34"}],"version-history":[{"count":6,"href":"https:\/\/danielbondurantcybersecurityportfolio.online\/index.php?rest_route=\/wp\/v2\/posts\/34\/revisions"}],"predecessor-version":[{"id":144,"href":"https:\/\/danielbondurantcybersecurityportfolio.online\/index.php?rest_route=\/wp\/v2\/posts\/34\/revisions\/144"}],"wp:attachment":[{"href":"https:\/\/danielbondurantcybersecurityportfolio.online\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danielbondurantcybersecurityportfolio.online\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danielbondurantcybersecurityportfolio.online\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}