I suggest that you have one entry that launches itself every 0th day (Sunday). That program would run as root and encapsulate the shutdown. That program would make some decisions based on the day of the week. If it is Sunday and the second Sunday of the month, then reboot the system.
The following is very crude, but it works. I'm sure if you Google, you'll find something better, but this is what I used. You could substitute the database table with a file.
My problem to be solved is I need to know if today is Monday, then is this the 1st or 3rd Monday of the month. If it is either, I do something different depending on 1st or 3rd Monday.
Here is some crude C code to get the day out of time. Ignore the IBM Informix calls.
Code:
int get_day_of_week_month(int nargs)
{
time_t now_time, timer;
struct tm * pnow_time;
int day_of_week;
int day_of_month;
now_time = time(NULL);
pnow_time = localtime(&now_time);
day_of_week = pnow_time->tm_wday;
day_of_month = pnow_time->tm_mday;
ibm_lib4gl_returnMInt(day_of_week);
ibm_lib4gl_returnMInt(day_of_month);
return 2;
}
If this returns that the day is a Monday, then
This select statement executes:
Code:
select d.monday
into first_monday
from day_of_week d
where d.week_number = 1
and d.monday = day_of_month
If not the first Monday --
Code:
where d.week_number = 1
-- then see if it's the third Monday,
Code:
select d.monday
into third_monday
from day_of_week d
where d.week_number = 3
and d.monday = day_of_month
Here's the contents of day_of_week. Both columns are smallint.
Code:
monday week_number
7 1
6 1
1 1
5 1
4 1
3 1
2 1
8 2
9 2
14 2
10 2
11 2
13 2
12 2
15 3
16 3
19 3
17 3
20 3
21 3
18 3
23 4
26 4
28 4
22 4
25 4
24 4
27 4
31 5
29 5
30 5