autoclear 自动清理过期文件 william 收录于 Tools2023-02-21 约 200 字 预计阅读 1 分钟 警告 本文最后更新于 2023-02-21,文中内容可能已过时。 自动清理超过一定时间的文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 #!/usr/bin/env bash mkdir -p $HOME/log LOG_FILE=$HOME/log/$(date +"%Y%m%d.MyLog.log") exec &> >(tee -a "$LOG_FILE") is_init=false msg () { echo -e "------------------------------------------------------------------" if [ !is_init ]; then is_init=true echo -e ">> $(date +'%Y-%m-%d %H:%M:%S') << '$0'" fi echo -e ">> $(date +'%Y-%m-%d %H:%M:%S') << '$1'" echo -e "-----------------------------------------------------------------" } msg "Run autoclear.sh" #datadir=$HOME/data datadir=/data xday=$(date -d "-30 days" +"%Y%m%d") for f in `ls $datadir`; do tmpdate=`date -r $datadir/$f "+%Y%m%d"` if [[ $tmpdate < $xday ]]; then echo "##==> now rm $f ==> [[ $tmpdate < $xday ]]" if [[ $f == *"tar.bz2"* ]]; then rsync -avPzr $datadir/$f ops:/data/Xtp/FromZZ.SZ fi rm -rf $datadir/$f fi done msg "Done!" 相关内容 常用音频、视频网站推荐 bashrc prompt 颜色设置 clickhouse 检查表最近修改时间 killx bwg 检查 IP 是否被墙 赞赏 支付宝 微信 Please enable JavaScript to view the comments powered by giscus.