{"id":12702,"date":"2024-10-28T07:46:58","date_gmt":"2024-10-28T14:46:58","guid":{"rendered":"https:\/\/www.coretechnologies.com\/blog\/?p=12702"},"modified":"2024-10-28T07:46:58","modified_gmt":"2024-10-28T14:46:58","slug":"run-batch-file-once-a-day","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/run-batch-file-once-a-day\/","title":{"rendered":"Q&#038;A: How Do I Run My Batch File Once A Day With AlwaysUp?"},"content":{"rendered":"<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"\/blog\/images\/qa-run-batch-file-once-daily.webp\" style=\"margin-bottom:20px;\" title=\"How Do I Run My Batch File Once A Day With AlwaysUp?\" alt=\"Q&#038;A: How Do I Run My Batch File Once A Day With AlwaysUp?\" border=\"0\" width=\"380\" height=\"160\" \/><\/div>\n<div class=\"blog-qa-question-box\">\n<img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"https:\/\/cdn.coretechnologies.com\/images\/quotes-transparent-21x21.webp\" width=\"21\" height=\"21\" \/>&nbsp;&nbsp;We have licensed AlwaysUp for each of our production servers and we use that to ensure some custom API programs are always running.<\/p>\n<p>We use <a href=\"\/products\/AlwaysUp\/ScheduledTaskVsAlwaysUp.html\">Windows Task Scheduler<\/a> to call a number of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Batch_file\" target=\"_blank\" rel=\"noopener\">batch files<\/a> that upload data once every night to cloud storage.  <\/p>\n<p>I do not recall seeing a way to configure AlwaysUp to run a batch file once a day and not bother about trying to keep the batch file always running.  <\/p>\n<p>Did I miss a configuration setting that lets me run a batch file once a day and not restart it when it finishes, until the next scheduled time?<\/p>\n<p align=\"right\">&mdash; RF<\/p>\n<\/div>\n<p>Hi RF, thanks for getting in touch.<\/p>\n<p>Yes &mdash; AlwaysUp can definitely help you run your batch file reliably each day. Here&#8217;s how to put that in place.<\/p>\n<h2 class=\"blog-caption\">Step 1: Install your batch file as a 24\/7 Windows Service with AlwaysUp<\/h2>\n<p>The first thing to do it to install your batch file in AlwaysUp. Our easy to use <a href=\"\/products\/AlwaysUp\/ApplicationAdvisor\/\">Application Advisor<\/a> will help you get you set up in a few minutes.<\/p>\n<p>Please:<\/p>\n<ol style=\"margin-bottom:24px\">\n<li>\n<p>In AlwaysUp, click the &#8220;magic wand&#8221; icon (<img loading=\"lazy\" decoding=\"async\" src=\"\/images\/alwaysup-application-advisor-48x48.png\" style=\"vertical-align:middle\" width=\"24\" height=\"24\"\/>) on the toolbar to launch the Application Advisor.<\/p>\n<\/li>\n<li>\n<p>Advance past the welcome page, choose <b>Batch file<\/b> from the list of applications, and click <b>Next<\/b> to proceed:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/alwaysup-advisor-choose-batch-file.png\" class=\"zoomPopup\" title=\"Choose Batch File\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/alwaysup-advisor-choose-batch-file.png\" title=\"Choose Batch File (click to enlarge)\" alt=\"Choose Batch File\" border=\"0\" \/><\/a><\/div>\n<\/li>\n<li>\n<p>Enter the full path to your batch file:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/alwaysup-advisor-enter-batch-file-path.png\" class=\"zoomPopup\" title=\"Enter the path to your batch file\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/alwaysup-advisor-enter-batch-file-path.png\" title=\"Enter the path to your batch file (click to enlarge)\" alt=\"Enter the path to your batch file\" border=\"0\" \/><\/a><\/div>\n<\/li>\n<li>\n<p>Next, enter the password for your Windows account:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/alwaysup-advisor-enter-windows-credentials.png\" class=\"zoomPopup\" title=\"Enter your Windows credentials\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/alwaysup-advisor-enter-windows-credentials.png\" title=\"Enter your Windows credentials (click to enlarge)\" alt=\"Enter your Windows credentials\" border=\"0\" \/><\/a><\/div>\n<\/li>\n<li>\n<p>Step through the rest of the process and click the <b>Save<\/b> button to add your batch file to AlwaysUp.<\/p>\n<\/li>\n<\/ol>\n<p>At this point, you have installed a batch file that AlwaysUp will run 24\/7 &mdash; automatically restarting it if it ever stops for any reason. But that&#8217;s not what you want, right? Not to worry &mdash; we&#8217;ll address that overzealousness in the next step.<\/p>\n<h2 class=\"blog-caption\">Step 2: Adjust your batch file to run once per day, at a set time<\/h2>\n<p>AlwaysUp features basic (but convenient) scheduling that allows customers to run programs periodically. You can find the relevant controls on the <b>Restart<\/b> tab when configuring your application.<\/p>\n<p>To run your batch file once daily &mdash; say, at 7 AM, before you get into the office:<\/p>\n<ol style=\"margin-bottom:24px\">\n<li>\n<p>Edit your application in AlwaysUp (by selecting <b>Edit\/View Application<\/b> from the <b>Application<\/b> menu).<\/p>\n<\/li>\n<li>\n<p>Switch to the <b>Restart<\/b> tab.<\/p>\n<\/li>\n<li>\n<p>Select the <b>Not immediately, but<\/b> option, select <b>At<\/b> and enter the time to run your batch file (7 AM):<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/alwaysup-run-every-day-7-am.png\" class=\"zoomPopup\" title=\"Run your application every day at 7 AM\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/alwaysup-run-every-day-7-am.png\" title=\"Run your application every day at 7 AM (click to enlarge)\" alt=\"Run your application every day at 7 AM\" border=\"0\" \/><\/a><\/div>\n<\/li>\n<li>\n<p>Save your settings.<\/p>\n<\/li>\n<\/ol>\n<p>Going forward, AlwaysUp will now launch your batch file at 7 every morning.<\/p>\n<h2 class=\"blog-caption\">One more consideration: Should your batch file run immediately when your AlwaysUp service starts?<\/h2>\n<p>If your goal is to run your batch file <u>only at 7 AM<\/u>, we actually have a bit more work to do. Let me explain.<\/p>\n<p>As you probably know, AlwaysUp installed a Windows Service to manage your batch file. That service is will ensure that your batch file runs every morning at 7. But there&#8217;s one more time when the service will run your batch file: <b>when the service starts<\/b>.<\/p>\n<p>For example, let&#8217;s say that your server reboots at 4:30 AM. Here&#8217;s what would happen:<\/p>\n<ul style=\"margin-bottom:24px\">\n<li>\n<p>4:31 AM: Windows starts your AlwaysUp batch file Windows Service.<\/p>\n<\/li>\n<li>\n<p>4:31 AM: The AlwaysUp service starts your batch file.<\/p>\n<\/li>\n<li>\n<p>4:36 AM: Your batch file exits (it ran for 5 minutes).<\/p>\n<\/li>\n<li>\n<p>4:36 AM: The AlwaysUp service notices that your batch file has exited. It queues up the next run for today at 7 AM.<\/p>\n<\/li>\n<li>\n<p>7:00 AM: The AlwaysUp service starts your batch file.<\/p>\n<\/li>\n<li>\n<p>7:05 AM: Your batch file exits (it ran for 5 minutes).<\/p>\n<\/li>\n<li>\n<p>7:05 AM: The AlwaysUp service notices that your batch file has exited. It queues up the next run for tomorrow at 7 AM.<\/p>\n<\/li>\n<\/ul>\n<p>So the question for you is: <b>Is it OK for AlwaysUp to run your batch file when the service starts?<\/b> Those extra, unscheduled runs can happen at any time &mdash; not only at 7 AM.<\/p>\n<h3>How to avoid unscheduled runs when the AlwaysUp service starts<\/h3>\n<p>If those additional, irregular invocations are unacceptable, then you must make one more change.<\/p>\n<p>Edit your entry in AlwaysUp, return to the <b>Restart<\/b> tab and check the <b>This delay applies to the first run as well<\/b> box:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/alwaysup-delay-first-run.png\" class=\"zoomPopup\" title=\"Delay the first run to 7 AM\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/alwaysup-delay-first-run.png\" title=\"Delay the first run to 7 AM (click to enlarge)\" alt=\"Delay the first run to 7 AM\" border=\"0\" \/><\/a><\/div>\n<p>With that change in place, here&#8217;s what would happen at our hypothetical reboot at 4:30 AM:<\/p>\n<ul style=\"margin-bottom:24px\">\n<li>\n<p>4:31 AM: Windows starts your AlwaysUp batch file Windows Service.<\/p>\n<\/li>\n<li>\n<p>4:31 AM: The AlwaysUp service schedules your batch file to run at 7 AM.<\/p>\n<\/li>\n<li>\n<p>7:00 AM: The AlwaysUp service starts your batch file.<\/p>\n<\/li>\n<li>\n<p>7:05 AM: Your batch file exits (it ran for 5 minutes).<\/p>\n<\/li>\n<li>\n<p>7:05 AM: The AlwaysUp service notices that your batch file has exited. It queues up the next run for tomorrow at 7 AM.<\/p>\n<\/li>\n<\/ul>\n<p>As you can see, the extra run at 4:31 AM wouldn&#8217;t happen.<\/p>\n<p style=\"margin-top: 30px\">\nAll the best running your batch file!\n<\/p>\n<div style=\"margin-top:30px\" align=\"center\">\n<div class=\"cta-button-1\">\n<table role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" align=\"left\">\n<tbody>\n<tr>\n<td align=\"center\"><a href=\"\/blog\/tag\/alwaysup-tag\/\" title=\"More articles about AlwaysUp\"><span><nobr>More articles about AlwaysUp&#8230;<\/nobr><\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/detect-endless-loop\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q&amp;A: Why Doesn&#039;t AlwaysUp Catch my Endless Loop?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/no-infinite-loops-150x150.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q&amp;A: Why Doesn&#039;t AlwaysUp Catch my Endless Loop?<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/windows\/windows-server-2025-preview\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Looking Good on Windows Server 2025\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/windows-server-2025-150x150-1.webp\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Looking Good on Windows Server 2025<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/survive-automatic-updates\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"How to Survive Automatic Updates when Running 24\/7 with AlwaysUp\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/auto-update-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">How to Survive Automatic Updates when Running 24\/7 with AlwaysUp<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp;We have licensed AlwaysUp for each of our production servers and we use that to ensure some custom API programs are always running. We use Windows Task Scheduler to call a number of batch files that upload data once every &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/run-batch-file-once-a-day\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":12706,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[26,44,127,164],"class_list":["post-12702","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-alwaysup","tag-alwaysup-tag","tag-batch-file","tag-qa","tag-task-scheduler"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/12702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=12702"}],"version-history":[{"count":10,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/12702\/revisions"}],"predecessor-version":[{"id":12728,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/12702\/revisions\/12728"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/12706"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=12702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=12702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=12702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}