{"id":285,"date":"2025-04-16T10:18:12","date_gmt":"2025-04-16T08:18:12","guid":{"rendered":"https:\/\/www.24x7serverguard.com\/blog\/?p=285"},"modified":"2025-04-16T10:18:12","modified_gmt":"2025-04-16T08:18:12","slug":"%f0%9f%95%92-how-to-set-a-cron-job-for-the-first-sunday-of-every-month-cpanel-alternative","status":"publish","type":"post","link":"https:\/\/www.24x7serverguard.com\/blog\/cpanel\/%f0%9f%95%92-how-to-set-a-cron-job-for-the-first-sunday-of-every-month-cpanel-alternative\/","title":{"rendered":"\ud83d\udd52 How to Set a Cron Job for the First Sunday of Every Month (cPanel Alternative)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Setting a cron job to run on the <strong>first Sunday of every month<\/strong> isn\u2019t directly possible using the default cPanel interface. However, with a simple script, you can easily work around this limitation and automate your tasks\u2014like running system updates or backups\u2014on schedule.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we\u2019ll walk you through a simple method to set up such a cron job using shell scripting.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 Why You Can\u2019t Use cPanel for This<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The cPanel cron job interface doesn\u2019t allow advanced conditions like \u201cfirst Sunday of the month.\u201d It only supports specific days, dates, and times, so this type of logic must be handled in a custom script.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd27 Method 1: Inline Cron Script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can set the cron job directly using an inline <code>if<\/code> statement in your crontab.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd01 Cron Expression:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">00 00 1-7 * * <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">if<\/mark> [<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\"> &#8220;$(date +\\%a)&#8221;<\/mark> = <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">&#8220;Sun&#8221;<\/mark> ]; <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">then <\/mark>\/script\/upcp; <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">fi<\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 What it does:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>00 00 1-7 * *<\/code> \u2014 Runs daily at <strong>midnight<\/strong> during the <strong>first 7 days<\/strong> of each month.<\/li>\n\n\n\n<li>The <code>if<\/code> condition checks if the current day is <strong>Sunday<\/strong>.<\/li>\n\n\n\n<li>If true, it executes <code>\/script\/upcp<\/code>.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\uddc2\ufe0f Method 2: Using an External Script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For better organization, especially in larger systems, you can offload the logic to a separate shell script.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udcc1 Step 1: Create a shell script<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a file called <code>\/home\/test.sh<\/code> and add the following code:<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">if <\/mark>[[ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">&#8220;$(date +&#8217;%a&#8217;)&#8221;<\/mark> != <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">&#8220;Sun&#8221;<\/mark> ]]; then<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">exit <\/mark>0<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">else<\/mark><br>\/script\/upcp<br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">fi<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure to give it execute permissions:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">chmod <\/mark>+x \/home\/test.sh<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd52 Step 2: Set the Cron Job<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now, add the following line to your crontab:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">00 00 1-7 * * \/home\/test.sh<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This cron runs every day from the 1st to the 7th at midnight, and the script takes care of executing the command only on Sunday.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">_____________________________________________________________________________________<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udca1 Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">While cPanel doesn\u2019t support scheduling cron jobs on the <strong>first Sunday of the month<\/strong> directly, these simple workarounds get the job done. Whether you choose an inline script or a dedicated <code>.sh<\/code> file, you can automate your tasks reliably.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting a cron job to run on the first Sunday of every month isn\u2019t directly possible using the default cPanel interface. However, with a simple script, you can easily work around this limitation and automate your tasks\u2014like running system updates or backups\u2014on schedule. In this guide, we\u2019ll walk you through a simple method to set [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":287,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[25,275,274,273,272],"class_list":["post-285","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpanel","tag-cpanel","tag-cron-expression","tag-inline-cron-script","tag-irst-sunday-of-every-month","tag-set-a-cron-job"],"_links":{"self":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/comments?post=285"}],"version-history":[{"count":1,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/285\/revisions"}],"predecessor-version":[{"id":288,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/285\/revisions\/288"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/media\/287"}],"wp:attachment":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/media?parent=285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/categories?post=285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/tags?post=285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}