inotify-tools
监控nginx配置
#!/bin/bash
NGINX_DIR="/etc/nginx"
LOG_FILE="/var/log/nginx_git_watch.log"
cd $NGINX_DIR || exit 1
inotifywait -m -r \
-e modify,create,delete,move \
--exclude '\.swp$|\.tmp$|\.log$|~$' \
$NGINX_DIR |
while read path action file; do
echo "$(date) - $action - $path$file" >> $LOG_FILE
# 防止频繁提交(1 秒内合并)
sleep 1
# 有变更才提交
if ! git diff --quiet; then
git add .
git commit -m "Auto update nginx config: $action $file"
git push origin main
fi
done