The schedule specification syntax is:
minute hour day month weekday
General logs of crontab can be viewed using the following command:
grep CRON /var/log/syslog
This probably requires to have rsyslog
installed.
If no logs show up, check the file /etc/rsyslog.d/50-default.conf
for a commented out line like #cron.*
and uncomment it. Then restart rsyslog
using service rsyslog restart
.
0 13 * * * call_to_script >> /home/log/myscript.log 2>&1
42 17 * * * command >>stdout.log 2>>stderr.log
0 13 * * * call_to_script 2>&1 | tee --append log_file 2>&1
This has the advantage, that the cronjob is observable, when run manually.
0 9 * * * command > /proc/1/fd/1 2>&1
The /proc/1/fd/1
is explained as follows: /proc/PID/fd/1
where /proc
is a conventional location, then follows the PID of the process whose file descriptors will be used, then /fd
, which stands for "file descriptors" and then /1
for stdout or /2
for stderr.
Docker always uses the stdout from process with PID 1 as the docker log stream, so redirecting output to /proc/1/fd/1
will make the output visible in docker logs ...
output.
0 9 * * * command > /proc/$(cat /var/run/crond.pid)/fd/1 2>&1
The /proc/1/fd/1
is explained as follows: /proc/PID/fd/1
where /proc
is a conventional location, then follows the PID of the process whose file descriptors will be used, then /fd
, which stands for "file descriptors" and then /1
for stdout or /2
for stderr.
$(cat /var/run/crond.pid)
will find the PID of the running cron process.