git - 监控 git repo 中更改的状态
问题描述
我正在使用Monit来监控 ubuntu 服务器,并希望对 git repo 中的更改进行测试。
我已经读过(这里)“git ls-files”将是做到这一点的最佳方式,但我不确定如何在 monit 中运行 exec 命令作为测试。他们的文档显示了在测试通过后运行 exec 命令的示例,但没有显示如何在 exec 上进行测试。
做这个的最好方式是什么?
==========
PS - 我根据下面的@TheCodeKiller 答案找到了解决方案。这是现在运行良好的最终代码。答案实际上在文档中,但我不认为它是我的解决方案。它就在这里。
内部监控配置(/etc/monit/monitrc):
check program changed_files with path "/path/to/git/directory/monit_alert_changed_files.sh"
if status != 0 for 3 cycles then alert
然后在该文件中:
#!/bin/bash
# Script to check if there are changes in the current git directory
if [[ `git --git-dir "/path/to/git/directory/.git" --work-tree "/path/to/git/directory/" ls-files -m -o --exclude-standard` ]]; then
# Changes
exit 1
else
# No changes
exit 0
fi
解决方案
您可以使用检查程序运行程序或自定义脚本:
check program my_check with path "/path/to/my/script.sh arg1 arg2 arg3"
if status != 0 for 3 cycles then alert
因此,您将不得不编写一个自定义脚本来执行此操作并根据脚本退出代码采取行动。
推荐阅读
- python - Python中的列表理解解决以下问题
- reactjs - 在 React 组件中调用内联函数 - React 测试库 + Jest
- c# - dotnet core -> 返回 jpg 图像的 base64 字符串时 web api 内容类型的最佳实践
- python - 使用 HTML 中的动态 URL 和按钮发布请求 Flask
- c# - 如何从 ASP.NET 样板中的用户表中删除电子邮件和其他额外字段?
- image - 如何在 Linux 中将 PNG 转换为未压缩的 DDS?
- performance - 使用 numpy 和 GPU 将矩阵乘以跨 Tenor 轴
- r - Plotly:如何使用 add_annotations 设置箭头的样式和颜色?
- azure - 将托管数据磁盘附加到 vm
- javascript - javascript:将函数分配给变量用未定义填充变量