阅读量:3
Ubuntu配置定时器常用cron和systemd timer两种方式,具体如下:
- 使用cron配置:
- 确保
cron服务已安装并启动:sudo apt install cron,sudo systemctl start cron,sudo systemctl enable cron。 - 编辑当前用户的
crontab文件:crontab -e。 - 按格式添加定时任务,如
0 8 * * * /path/to/script.sh(每天8点执行脚本)。 - 保存退出,可使用
crontab -l查看任务列表。
- 确保
- 使用systemd timer配置:
- 创建服务单元文件,如
sudo nano /etc/systemd/system/mytask.service,内容为[Unit] Description=My Task [Service] ExecStart=/path/to/script.sh。 - 创建定时器单元文件,如
sudo nano /etc/systemd/system/mytask.timer,内容为[Unit] Description=Run My Task [Timer] OnCalendar=*-*-* 08:00:00 Persistent=true [Install] WantedBy=timers.target。 - 重新加载
systemd配置:sudo systemctl daemon-reload。 - 启用并启动定时器:
sudo systemctl enable --now mytask.timer。
- 创建服务单元文件,如
以上就是关于“ubuntu 定时器如何配置”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm