PDA

Bekijk Volledige Versie : Crontab om de 2 weken



Aligno Internet
19/04/06, 23:45
Hey,

Ik wil vanaf woensdag 26 april om de 2 weken op een woensdag om 16:00 een script laten uitvoeren. Dit wil ik doen met een crontab in plesk. Omdat ik zeker wil weten dat dit goed gaat, ben ik benieuwd of de manier van uitvoeren die ik in gedachte heb goed is.

>> Minute: 0
>> Hour: 16
>> Day of the month: /14
>> Month: *
>> Day of the week: 3

Naar mijn weten heb ik nu ingesteld dat op een woensdag om 16:00 om de 14 dagen het script wordt aangeroepen. Is dat zo goed?

Als ik deze crontab instel op woensdag 26 april, wordt het script vanaf die datum elke woensdag om de 14 dagen aangeroepen. Op 26 april zelf voer ik het script dan 1 keer met de hand uit.

Ik hoop echt dat iemand weet of zo gebeurd wat ik wil bereiken.

Al vast bedankt

Dedicated
20/04/06, 13:32
Hey,

>> Minute: 0
>> Hour: 16
>> Day of the month: /14
>> Month: *
>> Day of the week: 3



Na mijn weten is /14 geen geldige invoer.
# Minute: 0 - 59 or *
# Hour: 0 - 23 or *
# Day of the Month: 1 - 31 or *
# Month: 1 - 12 or *
# Day of the Week: 0 - 6 (0 is Sunday) or *

Maar wat je eventueel wel kunt doen is hem bv op de 15 te zetten dat is ongeveer de helft van de maand, dan wel day of the week op * zetten. Dan wordt die om 2,2 a 2,3 weken uitgevoerd. Is dus ook bijna om de 14 dagen.

Pinocchi
20/04/06, 14:08
/14 kan wel, maar dan moet je er */14 van maken. zo roepen wij ook een aantal scripts op om de zoveel minuten.

Keenondots
20/04/06, 14:09
Zie: http://forums.hostmatters.com/archive/index.php/t-1091.html
(of Google verder)

ivs
20/04/06, 15:05
Volgens mij gaat dit niet werken zo.

*/14 voert het commando uit als de dag deelbaar is door 14, dus op 14e en de 28e maar deze maand vallen de woensdagen bijvoorbeeld op de 12e en de 26e dus gebeurd er niks. Alleen */14 zou wel kunnen alleen dat is dus niet altijd om de 2 weken.

Ik zou zelf gewoon voor een job gaan die iedere woensdag draait en dan zelf iets scripten dat er om de week niks gebeurd.

Misschien zou 1 1 */2 * 3 doen wat je wil maar ik ben er niet zeker van.

Aligno Internet
20/04/06, 18:15
Iedereen alvast bedankt voor de hulp.

Bij crontabs kan je een interval opgeven en dat doe je met het / teken. Een voorbeeld hiervan vond ik bij minuten en uren. Helaas niet over weken.

"If you wanted to run a cronjob every 5 minutes, you would be able to use */5 in the minutes column. If it was every 5 hours, then */5 could be placed in the hours column. Many would confuse this */5 as a fraction, but it is actually setting the frequency that the cron takes place in that column. It means ‘every five’ rather than a fifth of it."

Er is dus niemand die al eens om de 2 weken een cronjob heeft ingesteld, of weet hie dat moet? Ik kan nu helaas nog steeds niet aan de slag.

Keenondots
20/04/06, 18:54
Heb je de link die ik gepost heb bekeken? Daar staat je oplossing...


The easiest thing to do might be to schedule the job to run every Monday, then have some logic in the script itself to determine whether or not a backup is needed.

30 04 * * 1 backupscriptcommand

You don't say if 'backupscriptcommand' is a shell script, but assuming it is, something like this is all you need at the top:


#!/bin/bash

# set to 0 to skip even-numbered weeks, 1 to skip odd-numbered weeks
SKIPWEEK=0

# the number of the current week (01-52)
WEEK=`date +%V`

if [ `expr $WEEK % 2` -eq $SKIPWEEK ]; then
exit 0
fi

# rest of your backup script below

`expr $WEEK % 2` gives the remainder of the current week divided by 2. If the remainder is 0, this is an even-numbered week; if it's 1, this is an odd-numbered week. You choose which week to skip by setting the SKIPWEEK variable to 0 or 1.

This has the advantage of being easy to schedule in cron without relying on vixie cron goodies like the 'x/2' feature you were mentioning. Plus all the thinking about whether or not to run is in your script; you could add additional logic to determine other things about the backup job you want to run, possibly having the same script do partial backups sometimes, and full backups every two weeks.

It's not much overhead for a shell script to run often and decide to exit quickly. And it's certainly more flexible.