crontab

需求

定时清理指定目录下三天前的日志

delLogs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh
to_clear_dir=(1 2 3 4 5)
function cleanlog () {
for item in ${to_clear_dir[@]};
do
dir="/root/telephony-mock-server-"$item"/log/"
echo "开始删除系统目录: "$dir" 下前三天日志" >> /root/cron_task/task.log
time=`date +%T`
echo 该任务执行时间:`date +%Y-%m-%d` ${time} >> /root/cron_task/task.log
echo "删除日志清单列表:" >> /root/cron_task/task.log
find $dir -mtime +2 -name "*log*" >> /root/cron_task/task.log
find $dir -mtime +2 -name "*log*" -exec rm -f {} \;
echo "----------删除成功!-----------" >> /root/cron_task/task.log
done
}
cleanlog

加入crontab任务,执行:

1
crontab -e

就会显示出配置界面
crontab config

Author: Rick
Link: https://rcrick.github.io/2019/07/25/crontab/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Donate
  • 微信
  • 支付寶