如何将 cron 作业输出重定向到 stdout [英] How to redirect cron job output to stdout
本文介绍了如何将 cron 作业输出重定向到 stdout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 cron 作业,它的输出现在被重定向到一个文件中.如下图
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?
推荐答案
正在运行的进程有一个 PID,它的 fd(文件描述符)映射到 /proc/
.我们可以在 /var/run/crond.pid
中找到正在运行的 cron 进程的 PID.
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
.
要将 cron 日志发送到标准输出,我们可以将日志写入由 cron 启动的进程的第 1 个文件.
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
这篇关于如何将 cron 作业输出重定向到 stdout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文