Linux定期删除文件,并重定向到以日期命名的log的shell脚本

由于工作需要,写了个脚本定期删除归档文件,防止系统空间负载导致速度太慢

首先设置定时任务:

[root@EHP4 test1]# service crond start
[root@EHP4 test1]# vi crontest1.cron
[root@EHP4 test1]# crontab crontest1.cron
[root@EHP4 test1]# crontab -l

00 00 * * * /test1/test.sh >> /test1/$(date +"\%Y-\%m-\%d").log 2>&1	

 设置为每天0点定时执行test脚本,删除归档并重定向到以日期命名的log文件中。

然后是具体执行的脚本:

#!/bin/bash
find /oracle/DEV/oraarch/ -mtime +1 -name *.dbf -exec rm -rf {} \;

-mtime +1指的是删除一天前的文件

猜你喜欢

转载自blog.csdn.net/Franklin7B/article/details/82219025
今日推荐