大网数据广告活动
服务器运维问答

Where does the output of a script placed in /etc/cron.hourly go?

· 52CE 我爱测

Say I have a script named "testcron" containing the following: #!/bin/bash echo This script ran on $(date) I then set the permissions: chmod ug+x testcron Finally, I copy this script to /etc/cron.hourly And I wait for something t…

问题原文

原帖链接 · AWM · CC BY-SA 4.0

  1. Say I have a script named "testcron" containing the following:

    #!/bin/bash echo This script ran on $(date)

  2. I then set the permissions: chmod ug+x testcron

  3. Finally, I copy this script to /etc/cron.hourly

  4. And I wait for something to happen at the next hour.

So, I found in the /var/log/cron the following entry: Jul 17 12:01:02 localhost run-parts(/etc/cron.hourly)[13218]: starting testcron Jul 17 12:01:02 localhost run-parts(/etc/cron.hourly)[13240]: finished testcron

However, I could not find the script's actual output anywhere. Where does the output of this script go? Is it mailed? The root has no mail account. Can I redirect the mail to another user for just this script or will all mail output end up in the user's account? Does it go to /var/log/messages? What is the correct way redirect the output to, say, a dedicated log file?

Note: The script I included above doesn't actually do anything useful but I want to adapt the principles to another script that does.

OS: centos 7

Thanks to all in advance, Allan

已采纳解答

原帖链接 · notStan · CC BY-SA 4.0

On CentOS, it doesn’t seem to be logging output anywhere, just the fact that the cron has executed is stored in /var/log/cron.

If you need the output, you can use standard shell redirection. First create a file:

touch /var/log/cronoutput

Then capture the output of your cron, example:

* * * * * echo "hey" >> /var/log/cronoutput

Output:

tail /var/log/cronoutput
hey
hey
hey
hey

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-07-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。