I have a cron job and its output is now redirected into a file. It looks like the following
0 9 * * * /bin/sh /bin/cleanup.sh > /home/darkknight/cleanup.log
Can any one help me to rediect its output to stdout?
Like most daemons running on our system, the cron daemon logs its output somewhere under /var/log.
cron already sends the standard output and standard error of every job it runs by mail to the owner of the cron job. You can use MAILTO=recipient in the crontab file to have the emails sent to a different account.
It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .
Whenever a Crontab job is executed, an email regarding the execution of that job is sent to the email address of the root user i.e. the email ID that you have provided while configuring your Cron daemon.
Running process has a PID and its fd (file descriptor) is mapping to /proc/<PID>/fd
. And we can find PID of the running cron process at /var/run/crond.pid
.
To send cron log to stdout, we could write log to fd number 1 of the process started by cron.
0 9 * * * /bin/sh /bin/cleanup.sh > /proc/$(cat /var/run/crond.pid)/fd/1 2>&1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With