Debian – Cron allowed special character “L” for “Last day of the month” on Debian

crondebian

I'd like to know if L is one of the allowed special characters on Debian's cron implementation? I'm trying to set up a cron to run on the last day of every month.

From the cron entry on wikipedia:

'L' stands for "last". When used in the day-of-week field, it allows
you to specify constructs such as "the last Friday" ("5L") of a given
month. In the day-of-month field, it specifies the last day of the
month.

Note: L is a non-standard character and exists only in some cron
implementations (Quartz java scheduler)

If not, how would you go about setting a cron to run on the last day of every month? Would you recommend 3 different entries like this solution on stackoverflow?

Best Answer

Cron entries on Debian are described in the crontab man page (man 5 crontab). Debian uses Vixie's cron, and his man page says:

   The crontab syntax does not make it possible  to  define  all  possible
   periods  one could image off. For example, it is not straightforward to
   define the last weekday of a month. If a task needs to be run in a spe-
   cific  period of time that cannot be defined in the crontab syntaxs the
   best approach would be to have the program itself check  the  date  and
   time  information and continue execution only if the period matches the
   desired one.

   If the program itself cannot do the checks then a wrapper script  would
   be required. Useful tools that could be used for date analysis are ncal
   or calendar For example, to run a program the last  Saturday  of  every
   month you could use the following wrapper code:

   0 4 * * Sat   [ "$(date +%e)" = "`ncal | grep $(date +%a | sed  -e 's/.$//') 
     | sed -e 's/^.*\s\([0-9]\+\)\s*$/\1/'`" ] && echo "Last Saturday" &&
     program_to_run

So working along those lines:

   0 0 * * * perl -MTime::Local -e 
       'exit 1 if (((localtime(time()+60*60*24))[3]) < 2);' || program_to_run