linux计划任务

crond:是Linux系统中提供了计划任务的一个守护进程。
crontab 给 crond设置计划任务
crontab 给 crond送情报,告诉crond什么时间做什么事情

[root@localhost lianxi]# vim /etc/crontab 
# 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

在这里插入图片描述
在这里插入图片描述

创建计划任务:

[root@localhost lianxi]# crontab -e  创建计划任务   edit
30  3  7  12  *    bash /lianxi/backup_log.sh
[root@sanchuang lianxi]# crontab -e

第1步:按i进入计划任务的编辑模式,输入下面的内容
	0 23 * * *  bash /lianxi/backup_log.sh
第2步:按ESC,再输入:wq 退出并且保存

查看计划任务:

[root@localhost lianxi]# crontab -l  查看有哪些计划任务  list
30 3 7 12 *    bash /lianxi/backup_log.sh

删除计划任务:
推荐直接注释掉,不删除。

[root@localhost ~]# crontab -r

如何知道计划任务是否执行?
1.直接看效果
2.看日志

crontab的日志: 记录哪些计划任务的创建、执行、修改、查看等操作
	/var/log/cron
[root@sanchuang log]# tail -f cron

Mar 16 15:06:35 sanchuang crontab[22483]: (root) LIST (root)  查看
Mar 16 15:06:49 sanchuang crontab[22484]: (root) BEGIN EDIT (root)  编辑
Mar 16 15:07:07 sanchuang crontab[22484]: (root) REPLACE (root) 修改
Mar 16 15:07:07 sanchuang crontab[22484]: (root) END EDIT (root)  结束编辑
Mar 16 15:07:25 sanchuang crontab[22486]: (root) LIST (root)
Mar 16 15:08:01 sanchuang crond[22151]: (root) RELOAD (/var/spool/cron/root)  加载计划任务开始执行
Mar 16 15:08:01 sanchuang CROND[22491]: (root) CMD (bash /lianxi/sanchuang/create_dir.sh)
Mar 16 15:08:01 sanchuang CROND[22489]: (root) CMDOUT (tar: 从成员名中删除开头的“/)  脚本的执行输出效果


时间  地点  人物  发生的事情


CROND[22491]  CROND 是进程 [22491] 是crond的进程号 pid号

[root@sanchuang log]# ps aux|grep crond
root      22151  0.0  0.1  36332  3624 ?        Ss   13:08   0:00 /usr/sbin/crond -n
root      22518  0.0  0.0  12320   976 pts/1    R+   15:10   0:00 grep --color=auto crond
[root@sanchuang log]# 
CMD 表示执行命令 command

存放计划任务的文件夹

/var/spool/cron
用户定义的设置,位于文件:/var/spool/cron/用户名

/etc/下的这些文件夹里可以存放linux系统的计划任务
cron.d/       cron.daily/   cron.deny     cron.hourly/  cron.monthly/ crontab       cron.weekly/
cron.d/  存放计划任务的目录
cron.daily/ 存放每天需要执行的任务
cron.hourly/ 存放每小时需要执行的任务
cron.monthly/ 存放每月需要执行的任务
cron.weekly/  存放每周需要执行的任务
cron.deny   存放拒绝谁执行计划任务
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值