linux c语言定时任务crontab,linux定时任务 crontab

一、命令形式:

crontab命令的一般形式为:

crontab [-u user] file

crontab [ -u user ] [ -i ] { -e | -l | -r }

-e (编辑) -l (查看列表) -r (删除) -i (删除之前提示) 如果使用自己的名字登录,就不用使用-u选项,因为在执行crontab命令时,该命令能够 知道当前的用户

二、操作步骤

1、crontab -l 查看任务

2、如果有任务,crontab -e 按下边的格式添加任务 (nano编辑的control+X为退出,Y保存)

15 * * * * bash /opt/fyh/a.sh > ~/fyh/a.log

3、如果没有任务 编写 crontab文件 fyhcron

EDITOR=vi; export EDITOR

15 * * * * bash /opt/fyh/a.sh > ~/fyh/a.log

4、 crontab fyhcron 添加任务

5、 crontab -l 查看任务

6、 定时任务格式

第1列分钟1~5 9

第2列小时1~2 3(0表示子夜)

第3列日1~3 1

第4列月1~1 2

第5列星期0~6(0表示星期天)

第6列要运行的命令

三、cron的主配置

cron 是一个可以用来根据时间、日期、月份、星期的组合来调度对重复任务的执行的守护进程。cron的主配置文件/etc/crontab如下,定时执行相应任务

# /etc/crontab: system-wide crontab

# Unlike any other crontab you don't have to run the `crontab'

# command to install the new version when you edit this file

# and files in /etc/cron.d. These files also have username fields,

# that none of the other crontabs do.

SHELL=/bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user    command

17 *    * * *  root    cd / && run-parts --report /etc/cron.hourly

0  0    * * *  root    test -x      /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

47 6    * * 7  root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )

52 6    1 * *  root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

0  0    1 * *  root    /opt/ssl/renew_cert.sh >/dev/null 2>&1

#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值