Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5942749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:17:50+00:00 2026-05-22T16:17:50+00:00

I need to create a CRON job that will run on the last day

  • 0

I need to create a CRON job that will run on the last day of every month.
I will create it using cPanel.

Any help is appreciated.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:17:51+00:00Added an answer on May 22, 2026 at 4:17 pm

    Possibly the easiest way is to simply do three separate jobs:

    55 23 30 4,6,9,11        * myjob.sh
    55 23 31 1,3,5,7,8,10,12 * myjob.sh
    55 23 28 2               * myjob.sh
    

    That will run on the 28th of February though, even on leap years so, if that’s a problem, you’ll need to find another way.


    However, it’s usually both substantially easier and correct to run the job as soon as possible on the first day of each month, with something like:

    0 0 1 * * myjob.sh
    

    and modify the script to process the previous month’s data.

    This removes any hassles you may encounter with figuring out which day is the last of the month, and also ensures that all data for that month is available, assuming you’re processing data. Running at five minutes to midnight on the last day of the month may see you missing anything that happens between then and midnight.

    This is the usual way to do it anyway, for most end-of-month jobs.


    If you still really want to run it on the last day of the month, one option is to simply detect if tomorrow is the first (either as part of your script, or in the crontab itself).

    So, something like:

    55 23 28-31 * * [[ "$(date --date=tomorrow +\%d)" == "01" ]] && myjob.sh
    

    should be a good start, assuming you have a relatively intelligent date program.

    If your date program isn’t quite advanced enough to give you relative dates, you can just put together a very simple program to give you tomorrow’s day of the month (you don’t need the full power of date), such as:

    #include <stdio.h>
    #include <time.h>
    
    int main (void) {
        // Get today, somewhere around midday (no DST issues).
    
        time_t noonish = time (0);
        struct tm *localtm = localtime (&noonish);
        localtm->tm_hour = 12;
    
        // Add one day (86,400 seconds).
    
        noonish = mktime (localtm) + 86400;
        localtm = localtime (&noonish);
    
        // Output just day of month.
    
        printf ("%d\n", localtm->tm_mday);
    
        return 0;
    }
    

    and then use (assuming you’ve called it tomdom for “tomorrow’s day of month”):

    55 23 28-31 * * [[ "$(tomdom)" == "1" ]] && myjob.sh
    

    Though you may want to consider adding error checking since both time() and mktime() can return -1 if something goes wrong. The code above, for reasons of simplicity, does not take that into account.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a cron job that will tar all images created within
I want to create cron job that runs a script every 5 seconds. Seeing
I need to create a persistent Java based application that will run at set
Need to create a custom DNS name server using C which will check against
I am trying to setup an end-of-day automated email using a CRON job. I
I need unix cron command to run every 12 hours. I have 500+ sub
I have created a system that will be calculating data every month based on
We have a cron job that runs once a day and sends daily emails
I am in need to create a cron triggers expression which should fire on
Im trying to create a cron job involving aggregating emails sent within a period.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.