How can I set up my crontab to execute X script at 11:59PM every day without emailing me or creating any logs?
如何设置我的crontab以在每天晚上11:59执行X脚本而不通过电子邮件发送或创建任何日志?
Right now my crontab looks something like this
现在我的crontab看起来像这样
@daily /path/to/script.sh
3 个解决方案
#1
11
When you do crontab -e, try this:
当你做crontab -e时,试试这个:
59 23 * * * /usr/sbin/myscript > /dev/null
That means: At 59 Minutes and 23 Hours on every day (*) on every month on every weekday, execute myscript.
这意味着:在每个工作日的每个月的59分钟和23小时(*),执行myscript。
See man crontab for some more info and examples.
有关更多信息和示例,请参阅man crontab。
#2
6
Following up on svrist's answer, depending on your shell, the 2>&1 should go after > /dev/null or you will still see the output from stderr.
按照svrist的回答,取决于你的shell,2>&1应该在> / dev / null之后,否则你仍会看到stderr的输出。
The following will silence both stdout and stderr:
以下将使stdout和stderr沉默:
59 23 * * * /usr/sbin/myscript > /dev/null 2>&1
The following silences stdout, but stderr will still appear (via stdout):
以下沉默stdout,但stderr仍将出现(通过stdout):
59 23 * * * /usr/sbin/myscript 2>&1 > /dev/null
The Advanced Bash Scripting Guide's chapter on IO redirection is a good reference--search for 2>&1 to see a couple of examples.
“高级Bash脚本编制指南”中有关IO重定向的章节是一个很好的参考 - 搜索2>&1以查看几个示例。
#3
6
You will with the above response receive email with any text written to stderr. Some people redirect that away too, and make sure that the script writes a log instead.
您将使用上述回复接收带有写入stderr的任何文本的电子邮件。有些人也将其重定向,并确保脚本写入日志。
... 2>&1 ....
#1
11
When you do crontab -e, try this:
当你做crontab -e时,试试这个:
59 23 * * * /usr/sbin/myscript > /dev/null
That means: At 59 Minutes and 23 Hours on every day (*) on every month on every weekday, execute myscript.
这意味着:在每个工作日的每个月的59分钟和23小时(*),执行myscript。
See man crontab for some more info and examples.
有关更多信息和示例,请参阅man crontab。
#2
6
Following up on svrist's answer, depending on your shell, the 2>&1 should go after > /dev/null or you will still see the output from stderr.
按照svrist的回答,取决于你的shell,2>&1应该在> / dev / null之后,否则你仍会看到stderr的输出。
The following will silence both stdout and stderr:
以下将使stdout和stderr沉默:
59 23 * * * /usr/sbin/myscript > /dev/null 2>&1
The following silences stdout, but stderr will still appear (via stdout):
以下沉默stdout,但stderr仍将出现(通过stdout):
59 23 * * * /usr/sbin/myscript 2>&1 > /dev/null
The Advanced Bash Scripting Guide's chapter on IO redirection is a good reference--search for 2>&1 to see a couple of examples.
“高级Bash脚本编制指南”中有关IO重定向的章节是一个很好的参考 - 搜索2>&1以查看几个示例。
#3
6
You will with the above response receive email with any text written to stderr. Some people redirect that away too, and make sure that the script writes a log instead.
您将使用上述回复接收带有写入stderr的任何文本的电子邮件。有些人也将其重定向,并确保脚本写入日志。
... 2>&1 ....