可以的,Ubuntu 下常见的“定时器”有两种主流方案,都能做到每分钟执行一次:
Ubuntu 默认带 cron,支持最小粒度为 1 分钟。
* * * * * /path/to/your/script.sh
crontab -e
sudo systemctl status cron
⚠️ cron 最小只能到分钟,不能每秒执行。
如果你用的是 systemd(Ubuntu 16.04+ 基本都是),可以用 timer。
/etc/systemd/system/mytask.service
[Unit]
Description=My Task
[Service]
Type=oneshot
ExecStart=/path/to/your/script.sh
/etc/systemd/system/mytask.timer
[Unit]
Description=Run my task every minute
[Timer]
OnBootSec=1min
OnUnitActiveSec=1min
[Install]
WantedBy=timers.target
sudo systemctl daemon-reexec
sudo systemctl enable --now mytask.timer
systemctl list-timers
cron 和 systemd timer 都不直接支持每秒
常见做法:
sleep 1 循环watch -n 1 command✅ Ubuntu 定时器可以每分钟跑
✅ 推荐:简单任务用 cron
✅ 复杂/系统级任务用 systemd timer
如果你愿意,我可以帮你写一个具体例子(比如日志清理、健康检查等)。