Comments on: Last-day-of-month cron job https://backreference.org/2010/04/05/last-day-of-month-cron-job/ Proudly uncool and out of fashion Fri, 29 Jun 2012 13:07:32 +0000 hourly 1 https://wordpress.org/?v=5.8.2 By: waldner https://backreference.org/2010/04/05/last-day-of-month-cron-job/#comment-24766 Fri, 29 Jun 2012 13:07:32 +0000 http://backreference.org/?p=1141#comment-24766 In reply to kanchan.

In which way it does not work? Does the script run at all? You should be able to get some info from the cron log (don't know where it is on CentOS, may be /var/log/cron.log or /var/log/daemon.log or yet something else). Also make sure your cron support the 28-31 syntax (it should).

]]>
By: kanchan https://backreference.org/2010/04/05/last-day-of-month-cron-job/#comment-24765 Fri, 29 Jun 2012 12:43:58 +0000 http://backreference.org/?p=1141#comment-24765 Below is not working for me on linux centos machine.

Added below line /etc/crontab

0 23 28-31 * * root [ "$(/bin/date +\%d -d tomorrow)" = "01" ] && php /var/www/html/test/myfile.php

Please help

]]>
By: waldner https://backreference.org/2010/04/05/last-day-of-month-cron-job/#comment-24747 Wed, 21 Mar 2012 16:45:53 +0000 http://backreference.org/?p=1141#comment-24747 In reply to Chad.

You are right, percent signs need to be escaped in crontab files (I was even bitten recently by this). Thanks, I've updated the text.

]]>
By: Chad https://backreference.org/2010/04/05/last-day-of-month-cron-job/#comment-24746 Wed, 21 Mar 2012 16:41:16 +0000 http://backreference.org/?p=1141#comment-24746 In the GNU cron tab entry, I had to escape the % on a RHEL system.
0 23 28-31 * * [ "$(/bin/date +\%d -d tomorrow)" = "01" ] && /your/script.sh

]]>
By: Carl Wenninger https://backreference.org/2010/04/05/last-day-of-month-cron-job/#comment-24681 Thu, 18 Aug 2011 21:58:37 +0000 http://backreference.org/?p=1141#comment-24681 An excellent discussion of this topic!

Here is a C-Variant of the above Perl-Code.
The cmd-part of the crontab-line will look like
is-last-day-month && my-cron-job.sh

#include <time.h>

int main()
{
time_t t;

t = time(NULL) + 86400;
return localtime(&t)->tm_mday == 1;
}

]]>