将带有日期的 stderr 从 Cron 重定向到日志文件
bash 脚本从 cron 运行,stderr 被重定向到日志文件,这一切都工作正常。 代码是:
*/10 5-22 * * * /opt/scripts/sql_fetch 2>> /opt/scripts/logfile.txt
我想将日期添加到日志文件中的每一行,这不起作用,代码是:
*/10 5-22 * * * /opt/scripts/sql_fetch 2>> ( /opt/scripts/predate.sh >> /opt/scripts/logfile.txt )
predate.sh 脚本如下所示:
#!/bin/bash
while read line ; do
echo "$(date): ${line}"
done
所以第二位代码不起作用,有人可以解释一下吗? 谢谢。
A bash script is run from cron, stderr is redirected to a logfile, this all works fine.
The code is:
*/10 5-22 * * * /opt/scripts/sql_fetch 2>> /opt/scripts/logfile.txt
I want to prepend the date to every line in the log file, this does not work, the code is:
*/10 5-22 * * * /opt/scripts/sql_fetch 2>> ( /opt/scripts/predate.sh >> /opt/scripts/logfile.txt )
The predate.sh script looks as follows:
#!/bin/bash
while read line ; do
echo "$(date): ${line}"
done
So the second bit of code doesn't work, could someone shed some light?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一个小脚本 cronlog.sh 来执行此操作。脚本代码
然后你可以做
示例结果
I have a small script cronlog.sh to do this. The script code
Then you could do
Example result
应该正是你的方式。
should be exactly your way.