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
还没有评论,来说两句吧...