OpenVZ Forum


Home » General » Support » impossible values in /etc/crontab due to randomization
impossible values in /etc/crontab due to randomization [message #41005] Wed, 03 November 2010 12:06
rsauvat is currently offline  rsauvat
Messages: 5
Registered: May 2010
Junior Member
Hi.

I just realized that some of my /etc/crontab are set with impossible numbers for the hour field.
9  30  * * * root rm -f /var/spool/cron/lastrun/cron.daily

This seams to only appear on gentoo template and not debian/ubuntu for exemple.

This is the /etc/crontab from gentoo
# for vixie cron
# $Header: /var/cvsroot/gentoo-x86/sys-process/vixie-cron/files/crontab-3.0.1-r4,v 1.2 2009/05/12 09:13:46 bangert Exp $

# Global variables
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin 
MAILTO=root
HOME=/  

# check scripts in cron.hourly, cron.daily, cron.weekly and cron.monthly
3  *  * * * root rm -f /var/spool/cron/lastrun/cron.hourly
16  9  * * * root rm -f /var/spool/cron/lastrun/cron.daily
51 3  * * 6 root rm -f /var/spool/cron/lastrun/cron.weekly
32 3  1 * * root rm -f /var/spool/cron/lastrun/cron.monthly
*/10  *  * * * root test -x /usr/sbin/run-crons && /usr/sbin/run-crons 



And this is the part of the openvz script that set random times for cron.
cat crontab | awk '
BEGIN { srand(); }
{
        if ($0 ~ /^[ \t]*#/ || $0 ~ /^[ \t]+*$/) {
                print $0;
                next;
        }
        if ((n = split($0, ar, /[ \t]/)) < 7) {
                print $0;
                next;
        }
        # min
        if (ar[1] ~ /^[0-9]+$/) {
                ar[1] = int(rand() * 59);
        } else if (ar[1] ~/^-\*\/[0-9]+$/) {
                r = int(rand() * 40) + 15;
                ar[1] = "-*/" r;
        }
        # hour
        if (ar[2] ~ /^[0-9]+$/) {
                ar[2] = int(rand() * 6);
        }
        # day
        if (ar[3] ~ /^[0-9]+$/) {
                ar[3] = int(rand() * 31) + 1;
        }
        line = ar[1];
        for (i = 2; i <= n; i++) {
                line = line " "  ar[i];
        }
        print line;
}'


If you test it less than 10 times you will see an impossible value for the hour field.
If someone as a solution for this problem it would be great.
Previous Topic: vzpkg2 / pkg-cacher
Next Topic: Different subnets confusion
Goto Forum:
  


Current Time: Mon Sep 09 12:41:57 GMT 2024

Total time taken to generate the page: 0.04383 seconds