Linux中使用crontab实现定时任务

2023年 9月 28日 10.0k 0

crontab简介

crontab是一个用于在Linux系统上运行定时任务的工具。它允许用户以预先设定的时间间隔执行命令或脚本,例如每天、每周、每月或每分钟执行一次。crontab可以用于管理系统维护任务、备份、日志清理、自动化脚本等。用户可以通过编辑特定文件,在定时任务发生之前配置crontab。

ubuntu中使用crontab

安装:apt-get install cron
启动:service cron start
重启:service cron restart
停止:service cron stop
检查状态:service cron status
查询cron可用的命令:service cron
设置开机启动 sudo systemctl enable cron

centos中使用crontab

安装:yum install cron
启动:systemctl start crond
重启:systemctl restart crond
停止:systemctl stop crond
检查状态:systemctl status crond
查询cron可用的命令:systemctl crond -h
设置开机启动 sudo systemctl enable cron

crontab定时设置

sudo vim /etc/crontab
# 每分钟执行一次hello.sh
*/1 * * * * sh /tmp/hello.sh
# 参数说明
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

相关文章

猎豹浏览器怎么更改下载路径
Apache的URL缩短功能如何实现
Apache的点击劫持保护如何设置
Apache的HSTS功能是什么如何启用
Apache的X-Frame-Options如何配置以防止点击劫持
Apache的Content Security Policy如何设置

发布评论