Crontab configuration question
Hello,
I have been tasked with rebooting all our Linux Fedora 9 servers on the 2nd Sunday of every month at 8:15am. Since there was no way to specify 2nd Sunday in 1 configuration line I created 1 line for each month specifying the day of the month and month that the 2nd Sunday falls on each month. Is this correct and will it work like this, bypassing each line that doesn't apply and moving down the list to a line that does apply? # monthly reboot # 15 8 14 2 * /sbin/shutdown -r now 15 8 14 3 * /sbin/shutdown -r now 15 8 11 4 * /sbin/shutdown -r now 15 8 9 5 * /sbin/shutdown -r now 15 8 13 6 * /sbin/shutdown -r now 15 8 11 7 * /sbin/shutdown -r now 15 8 8 8 * /sbin/shutdown -r now 15 8 12 9 * /sbin/shutdown -r now 15 8 10 10 * /sbin/shutdown -r now 15 8 14 11 * /sbin/shutdown -r now 15 8 12 12 * /sbin/shutdown -r now ~ ~ "/tmp/crontab.XXXXS66Ltl" 15L, 396C Thanks in advance! Patrick |
Solved With DB Example
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) This select statement executes: Code:
select d.monday Code:
where d.week_number = 1 Code:
select d.monday Code:
monday week_number |
I'd go with a slightly more simple approach.
Code:
if [[ $(date "+%u") -eq 7 && $(date "+%e") -ge 8 ]]; then echo shutdown -r now; fi it must be the 2nd Sunday of that month), go and reboot. [edit]Oh, and as far as crontab goes: run daily ;}[/edit] Cheers, Tink |
Tinkster,
Thank you, that seems much simpler. But where do I put this command? In crontab file or somewhere else? I'm new to Linux and just starting to learn it, so pardon my ignorance if this is a dumb question. haha Thanks again |
Not dumb at all. I'd slap that into a shell-script, and point
cron at it. Code:
#!/bin/bash And then either symlink into /etc/cron.daily, or make it run every Sunday from roots crontab. Code:
15 8 * * Sun /sbin/schedule_reboot.sh test for Sunday anyway ;} So: Code:
#!/bin/bash Oooops.... slight oversight ... we don't want to boot every Sunday > 2nd ... So Code:
#!/bin/bash |
All times are GMT -5. The time now is 04:37 PM. |