Linux:定时任务配置

新增调度任务可用两种方法:

1)、在命令行输入: crontab -e 然后添加相应的任务,wq存盘退出。
test.sh,每分钟执行一次
(/1 * * * * /test/dingshi/test.sh >> /test/dingshi/result.log)
2)、直接编辑/etc/crontab 文件,即vi /etc/crontab,添加相应的任务。
(
/1 * * * * root /test/dingshi/test.sh >> /test/dingshi/result.log)
在这里插入图片描述
crontab -e配置是针对某个用户的,而编辑/etc/crontab是针对系统的任务

定时任务配置:

  • 1、编写需要定时跑的任务脚本

    cd /test/dingshi
    vim test.sh
    
    #!/bin/bash
    echo "test+$(date)";
    
  • 2、添加脚本到定时任务

     crontab -e
     输入定时命令
     */1 * * * * /test/dingshi/test.sh >> /test/dingshi/result.log
    
  • 3、定时任务配置完成。

linux系统:

查看系统是否有crontab服务:
service crond status/start/stop/restart
下载crontab服务:
yum install vixie-cron vixie-cron软件包是cron的主程序;
yum install crontabs crontabs软件包是用来安装、卸装、或列举用来驱动

查看crontab服务是否已设置为开机启动:
ntsysv

加入开机自动启动:
chkconfig -level 35 crond on
查看系统再跑的定时任务:
crontab -l

查看test用户的所有调度任务
crontab -l -u test

查看删除定时任务:
crontab -r

定时任务时间语法(cron):

分 小时 日月星期 命令
0-59 0-23 1-31 1-12 0-6 command

  • eg:0 18 * * * 每天下午六点
  • eg: */15 12 * * * 每天12点开始,每十五分钟执行一次

特殊符号:

  • “*”----取值范围内的数字,
  • “/”----”每”
  • “-”----从某个数字到某个数字
  • “,”---- 分开几个离散的数字
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xhaoDream

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值