【问题标题】:Apache ErrorLog write log and execute Python scriptApache ErrorLog 写入日志并执行 Python 脚本
【发布时间】:2014-06-26 13:19:28
【问题描述】:

我正在尝试将 Apache 2.4 错误写入错误日志并使用 Python 脚本将它们发送到 Graylog2 服务器。查看http://www.fnal.gov/docs/products/apache/syslog_logs_notes.htmlhttp://zindilis.com/docs/apache-logs-to-remote-syslog.html 等示例。示例显示我应该使用 tee,例如:

ErrorLog "| tee -a /var/log/httpd/error_log | nc -u -j syslog.example.com 514"

我正在做以下事情:

ErrorLog "| /usr/bin/tee -a /var/log/httpd/domains/test.error.log | /usr/bin/python /opt/apache2gelf/test.py"

消息被写入日志,但不执行 python 脚本。 Python 脚本有 755 个权限。我在这里错过了什么?

【问题讨论】:

  • 看起来不错。如何验证 Python 脚本没有被执行?
  • 听起来好像与tee 的缓冲区有关,我自己在过去使用过它。这可能会有所帮助:stackoverflow.com/questions/11337041/…
  • @Mikko 我正在写一些东西到一个文件来测试它。
  • @arco 你有我怎么做的例子吗?
  • 尝试不带 tee 进行测试?

标签: python apache graylog2


【解决方案1】:

试试:

ErrorLog "| /usr/bin/tee -a /var/log/httpd/domains/test.error.log | xargs /opt/apache2gelf/test.py"

并确保脚本的第一行是正确的解释器,例如 #!/usr/bin/env python

【讨论】:

  • 只写入错误日志,python脚本不写入测试文件。 Python 脚本的第一行是#!/usr/bin/env python
  • 我已经更新了答案“| xargs /opt/apache2gelf/test.py”中的命令,试试吧。
  • 不幸的是,我得到的结果与以前完全相同。
猜你喜欢
  • 2023-01-14
  • 1970-01-01
  • 1970-01-01
  • 2014-03-02
  • 1970-01-01
  • 2014-03-24
  • 1970-01-01
  • 1970-01-01
  • 2021-05-21
相关资源
最近更新 更多