在Ubuntu中,可通过以下方式自定义触发器:
sudo vim /etc/systemd/system/my-trigger.service
,在[Unit]
中描述触发器,在[Service]
中指定执行的脚本或命令,再通过sudo systemctl enable
和sudo systemctl start
命令启用和启动服务。inotify-tools
,再创建监控脚本,如#!/bin/bash inotifywait -m /path/to/monitor -e create,modify,delete
,通过判断文件事件来触发相应操作,最后给脚本添加可执行权限并运行。crontab -e
命令编辑当前用户的crontab文件,添加如@reboot /path/to/your/script.sh
或0 2 * * * /path/to/your/script.sh
等内容,设置触发时间和要执行的脚本。