linux centos 定时任务

本次使用centos 8系统
1.创建脚本(/usr/local/test/目录下)
创建删除文件   touch 1.txt
创建脚本    touch test.sh
vi test.sh

#! /bin/bash
echo "hello world"
rm -rf /usr/local/test/1.txt
echo "删除成功"

保存成功后,给文件增加可执行权限   chmod +x test.sh  或者给与最大权限 chmod 777 test.sh

2.配置定时任务
crontab -e   进行编辑 ,新增如下:


 当我们编辑完定时任务过后,记得重载一遍crond,只有重载了才有效
systemctl reload crond.service

常用命令如下:
crontab -l查看任务
启动、停止、重启服务↓
systemctl start crond.service
systemctl stop crond.service
systemctl restart crond.service

重点:vi /etc/crontab   编辑这个文本,启动,装载后不起作用,所以要使用crontab -e

文章来源:https://blog.csdn.net/weixin_41558061/article/details/80268639

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章