我正在尝试通过 cron 重新启动系统进程,并通过电子邮件接收该进程的启动输出。我以为将 STDOUT 和 SDTERR 重定向到 /dev/null 会“静音”输出,但遗憾的是,这不起作用。我如何让 cron 静默重新启动此服务?crontab 条目:
0 6 * * * service sympa stop &>/dev/null; service sympa start &> /dev/null
重启电子邮件的示例输出:
Stopping Sympa bounce manager bounced
...done.
* Stopping Sympa task manager task_manager
...done.
* Stopping Sympa mailing list archive manager archived
...done.
* Stopping Sympa mailing list manager sympa
...done.
... waiting Prototype mismatch: sub Lock::LOCK_SH () vs none at /home/sympa/bin/Lock.pm line 38.
Constant subroutine LOCK_SH redefined at /home/sympa/bin/Lock.pm line 38.
Prototype mismatch: sub Lock::LOCK_EX () vs none at /home/sympa/bin/Lock.pm line 39.
Constant subroutine LOCK_EX redefined at /home/sympa/bin/Lock.pm line 39.
Prototype mismatch: sub Lock::LOCK_NB () vs none at /home/sympa/bin/Lock.pm line 40.
Constant subroutine LOCK_NB redefined at /home/sympa/bin/Lock.pm line 40.
答案1
我认为你会想要下面这行
service sympa stop >/dev/null 2>&1
。
第一个命令将标准输出发送到/dev/null
然后2>&1
导致stderr (standard error)
发送到stdout(standard output)
要去的地方,/dev/null
从而抑制输出。