Last Day of Month Handling #688
Replies: 2 comments 1 reply
-
This feature is coming natively in Cronicle v2. There is a hack you can use in Cronicle v1 to achieve the effect. Use the Shell Plugin for your event, and add this code to wrap your own command: #!/bin/bash
# Get today's date and the date of the next day
today=$(date +%Y-%m-%d)
next_day=$(date +%Y-%m-%d -d "$today + 1 day")
# Extract the month from both dates
month_today=$(date -d "$today" +%m)
month_next_day=$(date -d "$next_day" +%m)
# Compare the months
if [ "$month_today" != "$month_next_day" ]; then
echo "Today is the last day of the month."
###
# Execute your command here
###
else
echo "Today is not the last day of the month."
fi Then set your event to run on the 28th, 29th, 30th and 31st days of the month. On the "real" last day of the month, your command will be executed. On the other days, the job will run, but it will just exit without doing anything. Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
All you need to do is only run if 'tomorrow' is the first of the month if [ $(date --date "tomorrow" +%d) -eq 1 ]; then |
Beta Was this translation helpful? Give feedback.
-
Does anyone have a method for handling the creation of an event that is to run on the last day of the month? In our current setup, our only option seems to be to create 3 schedules if the user wants their schedule to run on the last day of the month. I expect a Cronicle event set to run monthly on the 31 to run only on months that have a 31st. All ideas welcome and appreciated!
Beta Was this translation helpful? Give feedback.
All reactions