Ubuntu中有多种定时器命令,以下是一些常用的:
croncron 是一个时间基的作业调度器,用于在指定的时间执行任务。
编辑crontab文件:
crontab -e 查看crontab任务:
crontab -l 删除crontab任务:
crontab -r 示例任务(每分钟执行一次):
* * * * * /path/to/command atat 命令允许用户在指定的时间执行一次性任务。
提交任务:
echo "/path/to/command" | at now + 1 minute 查看待处理任务:
atq 删除待处理任务:
atrm <job_id> systemd对于使用 systemd 的系统,可以使用 systemd 定时器来调度任务。
创建定时器单元文件:
[Unit] Description=Run my script every hour [Timer] OnCalendar=*-*-* *:00:00 Persistent=true [Install] WantedBy=timers.target 启用并启动定时器:
systemctl enable mytimer.timer systemctl start mytimer.timer 查看定时器状态:
systemctl list-timers --all anacronanacron 是一个简单的作业调度程序,适用于那些不能保持24/7运行的系统。
配置文件:通常位于 /etc/anacrontab
示例条目:
period delay job-identifier command atdatd 是 at 命令的守护进程,负责处理 at 任务。
启动服务:
sudo systemctl start atd 设置开机自启:
sudo systemctl enable atd cron 和 at 时,确保脚本具有可执行权限。Celery 或 APScheduler。希望这些信息对你有所帮助!如果有其他问题,请随时提问。