Skip to content

Instantly share code, notes, and snippets.

@x-yuri
Last active February 11, 2021 21:00
Show Gist options
  • Save x-yuri/ca46523a1c7a2a803c603bc426bb1b27 to your computer and use it in GitHub Desktop.
Save x-yuri/ca46523a1c7a2a803c603bc426bb1b27 to your computer and use it in GitHub Desktop.
#dcron #cron #docker #alpine

Running dcron in a docker container

a.sh:

#!/bin/sh -eu
docker run --rm -v $PWD/crontab:/etc/crontabs/root -v $PWD/output.sh:/output.sh alpine sh -euxc '
    apk add dcron
    chown root: /etc/crontabs/root
    crond -fM /output.sh
'

crontab:

* * * * * whoami; date

output.sh

#!/bin/sh -eu
{ echo "$0 (`whoami`)"
echo '<<<'
cat
echo '>>>'; } >/proc/1/fd/1
$ ./a.sh
...
Wakeup dt=18
scheduled: user root whoami; date
FILE /etc/crontabs/root USER root PID  13 whoami; date
child running: whoami; date
exit status 0 from user root whoami; date
/output.sh (root)
<<<
To: root
Subject: cron for user root whoami; date

root
Thu Feb 11 20:31:01 UTC 2021
>>>
Wakeup dt=0

output.sh works only for root crontabs, since the mailer is run under the target user.

By default it starts with log level notice, add -l info to get a line for each job, or -d for debug output.

The debian version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment