// you’re reading...

How in the Tech

Is this the Last Day of the Month?

“One of the issues that has long irritated Unix users when setting up cron jobs is how to set up a job to run on the last day of the month. Unless one wants to set up a separate cron job for every month (and this still leaves the problem of leap years), it isn’t at all straightforward how to attack this seemingly ordinary problem with an ordinary solution. However, there are some reliable ways to code around the problem.”

I’ve come across this problem in my profession and my solution is much simpler and easier to understand than the one proposed in this verbose write-up.

#!/bin/bash
if [ `date --date="+1 day" +%d` = 01 ]; then
execute desired task
fi

Have cron execute this bash script at the desired run-time each day to achieve the desired results.

Plug. Chug. Done.

read more | digg story

Related Posts with Thumbnails

Discussion

No comments for “Is this the Last Day of the Month?”

Post a comment