I need a reminder every 4th Monday (= every 28 days) from the Monday I start counting. So I thought I can have ruby script
to send me an email ( I know how so do this part )
every 4th Monday , not every 4th Monday of a month. ( <--- how to code this bit in ruby? )
I will run the ruby scrip via cron every Monday ....
Assuming you've already determined that it's a Monday, then count the days since the beginning of the year (yday()), modulus by 28, and see if the result is in 22 and 27 (inclusive) or is 0.
Given a starting (initial run) date, you can just use step(28) to get the next date and if it equals the current date, run and then store that for your next run.
As an aside, if you had meant the 4th Monday in the month, check the current day of the Month, and if it's between the 22nd and 28th of the month, you're in the fourth occurance of that day of the week that month.
Give this a try. Whenever is cron for ruby.
This gentleman calculated the first week of the month, if you're running your script every Monday by cron, then you only need to find out if it is the 4th week of the month by ruby.
http://www.ruby-forum.com/topic/95015
I think you should use these two ruby gems:
To set a cron job -> WHENEVER - https://github.com/javan/whenever
gem install whenever
To send an email (obviously) -> GMAIL - https://github.com/nu7hatch/gmail
gem install gmail
Good Luck :D
Related
I need to complete timesheet of work until midnight of every last day of month. Since it's easy to forget, I want to set reminder on say 1PM of the last day. What's the correct syntax to configure it?
All my attempts either don't work or are clumsy:
/remind me "Complete timesheet!!!" at 13:00 on the last day of every month - sets 1st instead and does not completely understand
/remind me "Complete timesheet!!!" at 13:00 on the 31st of every month - works for 31-day-long months, ignores for shorter months
/remind me "Complete timesheet!!!" at 13:00 on the 30st of every month - (I guess) works every month except February, for 30-day-long months one can manually snooze by day
/remind me "Complete timesheet!!!" at -11:00 on the 1st of every month - sets 1st instead and does not completely understand
/remind me "Complete timesheet!!!" 11 hours before 1st day of every month - sets 1st instead and does not completely understand
12x copy of /remind me "Complete timesheet!!!" at 13:00 every November 30th for literally mentioned last day of every month - works but too lengthy
I will also accept answer with link to any documentation with formalized syntax of /remind command (BNF, railroad diagram) from which the possibility of such command would be either provable or disprovable.
How can i set Scheduler of Ibm on the first Monday of the week? If i set DayOfMonth 1-7 and DayOfTheWeek 2 together receive an error. Is not good simbol as 2#1
The error is consistent with the documentation
https://www.ibm.com/docs/en/was-zos/8.5.5?topic=SS7K4U_8.5.5/com.ibm.websphere.javadoc.doc/web/apidocs/com/ibm/websphere/scheduler/UserCalendar.html
which states, "The day of week and day of month terms cannot be specified at the same time. One must be a '?' and the other a term."
Regarding your question, you asked about the "first Monday of the week". Did you mean first Monday of the month?
Here is an example of Monday of every week at 8am:
0 0 8 ? * MON
where the Scheduler cron terms are
second minute hourOfDay DayOfMonth Month DayOfWeek
If you want only the first Monday of the month, the Scheduler CRON doesn't have a way to do it.
An easy, but inefficient, solution would be to use the syntax for every Monday and have your task logic return immediately and skip itself if not a first Monday.
You also have the option of supplying your own UserCalendar implementation to implement customized scheduling:
https://www.ibm.com/docs/api/v1/content/SS7K4U_8.5.5/com.ibm.websphere.javadoc.doc/web/apidocs/com/ibm/websphere/scheduler/TaskInfo.html#setUserCalendar(java.lang.String,%20java.lang.String)
I am trying to find the same day of week from last month if today's date is Wednesday Oct 2nd 2019. I need to retrieve Wednesday Sept 4th 2019.
I am using Carbon and have tried subDays(30) and subMonth(1) but that obviously doesn't return the same week day.
SalesLogs::loadByDate(Carbon::now()->subMonth(1));
This code works as expected, however I am unable to work out how to make it find the same day of the week based on the prior month.
It's not super clear what you are trying to do, but I will take a shot at it. What about if you subtract a month, and then go to the next matching weekday?
$weekday = now()->dayOfWeek;
SalesLogs::loadByDate(now()->subMonth(1)->next($weekday));
Note: you can take advantage of Laravel's handy now() helper function, which is equal to Carbon::now(), but saves you from having to import Carbon.
Does that get you what you need?
I want to schedule to run a shell script on a Thursday which comes after the second Tuesday of every month. How to schedule this in crontab?
The second Tuesday of the month will occur between the 8th and the 14th inclusive, so set the day-of-week field to 4 (Thursday), and the day-of-month field to 10-16 (that is, a range adjusted to be two days after the range of the month's second Tuesday).
E.g. the schellscript will not run on april 18, 19 and 20 and then for may is 16, 17 and 18 and so on
You can get the weekday in numerical form from the date command using date "+%w".
The output will be 0 for Sunday, 1 for Monday etc.
You can get the day of the month using date "+%d". Subtract one from that and divide by 7; that will give you how many complete weeks there have been in the current month.
From there, it's just a simple bunch of if/then statements. If you need more help actually implementing this, just ask.
Hope that helps!
I would advise to use cron for this kind of things, to separate the planned execution from what the script really does.
Have a look here on how to use cron.