Ubuntu 触发器的扩展思路与实现

一、先明确“触发器”的类型
二、按场景给出可扩展方案
三、最小可用示例
systemd 路径触发 + 定时器
#!/usr/bin/env bashset -eLOG=/var/log/trigger-demo.logecho "$(date) path changed: $1" >> "$LOG"chmod +x /usr/local/bin/trigger-handler.sh
# /etc/systemd/system/trigger-handler.service[Unit]Description=Handle path trigger[Service]Type=oneshotExecStart=/usr/local/bin/trigger-handler.sh "%f"systemctl daemon-reloadsystemctl enable --now trigger-handler.service
# /etc/systemd/system/trigger.path[Unit]Description=Watch /opt/incoming[Path]PathModified=/opt/incoming[Install]WantedBy=multi-user.targetsystemctl daemon-reloadsystemctl enable --now trigger.path
# /etc/systemd/system/trigger-timer.timer[Unit]Description=Run trigger every 5 minutes[Timer]OnCalendar=*:0/5Persistent=true[Install]WantedBy=timers.target# /etc/systemd/system/trigger-timer.service[Service]Type=oneshotExecStart=/usr/local/bin/trigger-handler.sh "timer"systemctl daemon-reloadsystemctl enable --now trigger-timer.timersystemctl list-timers trigger-timer.timer
inotify 文件监听
sudo apt-get install inotify-toolsinotifywait -m -e create,modify,delete /opt/incoming --format '%e %w%f' | while read ev file; doecho "$(date) $ev $file" >> /var/log/inotify-demo.log# 可在此调用你的业务脚本done四、扩展时的稳定性与维护建议
Visual-Studio怎样快速查找变量或方法-Visual-Studio如何快速找到变量或方法
如何用excel绘制三维立体饼图-excel三维立体饼图设计方法
住小帮测试装修风格的方法-住小帮如何测试装修风格
软媒魔方如何关闭Cortana小娜-软媒魔方怎么禁用语音助手Cortana释放资源
安卓转iOS必备应用推荐:跨平台迁移工具与软件排行榜
Visual-StudioCode怎么关闭自动存储库检测子文件夹-Visual-StudioCode怎样关闭自动存储库检测子文件夹