1、安装cron
# 安装
apt-get install cron
2、常用命令
# 查看状态
sudo systemctl status cron
# 开启服务
sudo systemctl start cron
# 停止服务
sudo systemctl stop cron
# 重启服务
sudo systemctl restart cron
3、编写要定时执行 hello.sh 脚本
#!/bin/bash
echo "Hello"
4、确保脚本有可执行权限
chmod +x hello.sh
5、打开当前用户的crontab定时任务列表
注:没有则会新建文件,位置在:/var/spool/cron/crontabs/下。Ctrl+X保存
crontab -e
6、在crontab文件中添加定时任务
例:每5分钟运行一次hello.sh脚本
*/5 * * * * /mnt/project/sinotmemc/check/hello.sh

文章介绍了如何在Ubuntu系统上安装和配置cron服务,以定时执行名为hello.sh的脚本。步骤包括安装cron,编写脚本,赋予脚本执行权限,使用crontab编辑器设置定时任务,以及查看和删除crontab任务。同时,文章提供了Crontab时间格式的说明。
最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



