700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > linux c语言定时任务crontab linux定时任务 crontab

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

时间:2019-08-03 13:36:58

相关推荐

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

#

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。