crontab计划定时任务

 

参数简介:

Crontab –u root #指定root用户的cron服务

Crontab -l 列出当前用户下    cron服务

Crontab –r #删除crontab服务

Crontab -e 编辑cront 服务

*代表取值 范围内的数字 任意

/ 指定时间的间隔频率   */10   0-23/2

查看创建计划的用户

/var/spool/cron/

Crontab格式

Vim /etc/crontab     #分,时,日,月,周 命令

查看服务状态

Systemctl status crond

[root@localhost ~]# crontab -l

36 23 * * * /root/a.sh

01 08 * * * echo "hello" > /root/a.txt

 

实例:

每天2:00备份/etc/目录到/tmp/backup下面

将备份命令写入一个脚本中

每天备份文件名要求格式: 2017-08-19_etc.tar.gz

在执行计划任务时,不要输出任务信息

存放备份内容的目录要求只保留三天的数据

====================================================

mkdir /tmp/backup

tar zcf etc.tar.gz /etc

find /tmp/backup -name *.tar.gz -mtime +3 -exec rm -rf {}\;

============================================================

[root@test ~]# crontab -l

13 21 * * * echo "hello" > /tmp/a.txt

0 22 * * * /root/backup.sh &> /dev/null

[root@test ~]# cat backup.sh

#!/bin/bash

find /tmp/backup -name "*.tar.gz" -mtime +3 -exec rm -f {}\;

#find /tmp/backup -name "*.tar.gz" -mtime +3 -delete

#find /tmp/backup -name "*.tar.gz" -mtime +3 |xargs rm -f

tar zcf /tmp/backup/`date +%F`_etc.tar.gz /etc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值