可以的,Debian 下的定时器完全支持每分钟执行,具体取决于你用的是哪一种“定时器”:
cron(最常见)Debian 默认自带 cron,最简单的方式:
* * * * * /path/to/script.sh
含义:
*:每分钟*:每小时、每天、每月、每周✅ 支持每分钟执行
✅ 系统自带,无需额外服务
systemd timer(现代方式)如果你用的是 systemd(Debian 8+ 基本都是),也可以:
/etc/systemd/system/mytask.service
[Unit]
Description=My per-minute task
[Service]
Type=oneshot
ExecStart=/path/to/script.sh
/etc/systemd/system/mytask.timer
[Unit]
Description=Run every minute
[Timer]
OnCalendar=*:0/1
Persistent=true
[Install]
WantedBy=timers.target
systemctl daemon-reload
systemctl enable --now mytask.timer
✅ OnCalendar=*:0/1 表示每分钟
✅ 比 cron 更适合系统服务管理
OnCalendar=*:*:0,30sleep| 场景 | 推荐 |
|---|---|
| 简单脚本 | cron |
| 系统服务 / 日志管理 | systemd timer |
| 需要秒级 | 自己写循环脚本 |
如果你愿意,可以告诉我:
我可以帮你直接写完整配置。