Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect cron job output to stdout

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 image 608
shafeeq Avatar asked Apr 06 '16 04:04

shafeeq


People also ask

Where does output from cron jobs go?

Like most daemons running on our system, the cron daemon logs its output somewhere under /var/log.

How do I store the output of a cron job?

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.

What is the use of * * * * * In cron?

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 .

How do I get mail from crontab?

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.


1 Answers

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 
like image 173
gaga5lala Avatar answered Oct 19 '22 18:10

gaga5lala