[Python] cronjob hour setting is being ignored in docker alpine container

Discussão em 'Python' iniciado por Stack, Abril 28, 2025.

  1. Stack

    Stack Membro Participativo

    I created a script called 'main.py' that does a little web scrape and sends an e-mail with SMTP. I set up a cron job to run the script three times a day - at 12:00, 18:00 and 21:00 (UTC-3). I didn't changed the docker image's tz so it runs in UTC0.

    Here's the cron job I added:

    0 15,21,24 \* \* \* python /app/main.py \>\> /var/log/cron.log 2\>&1

    However, the script main.py is being called every hour, respecting only the minutes field in the cron job (for example, if i change to

    0,15,20 15,21,24 \* \* \* python /app/main.py \>\> /var/log/cron.log 2\>&1

    it runs hourly, at minutes 0, 15 and 20 minutes.

    Bellow is my .sh script for the container to run

    #!/bin/bash

    set -e

    echo "Starting Xvfb..."
    Xvfb :99 -screen 0 1280x1024x24 -nolisten tcp -ac &

    sleep 3

    echo 'starting cron'
    crond -f -l 8 &

    tail -f /var/log/cron.log


    And here is my dockerfile:

    FROM python:3.11-alpine

    ENV DISPLAY=:99
    WORKDIR /app
    COPY . /app


    COPY cron_job /etc/crontabs/root


    RUN touch /var/log/cron.log

    RUN apk update && \
    apk add \
    gcc \
    g++ \
    musl-dev \
    libffi-dev \
    make \
    libc++ \
    libc++-dev \
    && apk add --virtual .build-deps gcc g++ make musl-dev

    RUN apk update && \
    apk add \
    firefox \
    dbus \
    ttf-freefont \
    xorg-server \
    xf86-video-vesa \
    bash \
    curl \
    unzip \
    xvfb-run \
    su-exec \
    libjpeg \
    libpng


    RUN apk add --no-cache bash curl busybox-suid && \
    chmod u+s /bin/busybox


    RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.36.0/geckodriver-v0.36.0-linux64.tar.gz
    RUN tar -xzf geckodriver-v0.36.0-linux64.tar.gz
    RUN mv geckodriver /usr/local/bin/geckodriver
    RUN chmod +x /usr/local/bin/geckodriver

    RUN pip install --upgrade pip && \
    pip install -r requirements.txt

    RUN chmod +x shebang.sh
    CMD \["./script.sh"\]

    Continue reading...

Compartilhe esta Página