linux – 如何记录cron执行所花费的时间.

前端之家收集整理的这篇文章主要介绍了linux – 如何记录cron执行所花费的时间.前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个cron设置每分钟运行
  1. * * * * * /usr/PHP /my/location/script.PHP

现在,我使用time函数来测量脚本执行时间.所以,跑步

  1. console$time /usr/PHP /my/location/script.PHP

输出

  1. real 0m0.000s
  2. user 0m0.000s
  3. sys 0m0.000s

但它不适用于这样的cron:

  1. * * * * * time /usr/PHP /my/location/script.PHP 2>&1 >> my_log_file

它也不能在命令行上运行

  1. console$time /usr/PHP /my/location/script.PHP >> my_log_file

在上面的两个示例中,time函数实际上计算写入my_log_file所花费的时间,而不是将其输出写入日志文件.
在脚本中添加代码并记录STD OUTPUT不是一个选项.

解决方法

关于什么:
  1. * * * * * (time /usr/PHP /my/location/script.PHP) >>my_log_file 2>&1

猜你在找的Linux相关文章