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.