From 887ebb35c732d8d900a3259b25af98718818f090 Mon Sep 17 00:00:00 2001 From: yaokai13 Date: Thu, 8 Apr 2021 10:40:06 +0800 Subject: [PATCH] delete_iso.sh --- script/tools/delete_iso.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 script/tools/delete_iso.sh diff --git a/script/tools/delete_iso.sh b/script/tools/delete_iso.sh new file mode 100644 index 0000000..de73ad9 --- /dev/null +++ b/script/tools/delete_iso.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# usage: bash delete_iso.sh +echo "--------------- start delete older iso ----------------" +DIR=$1 +my_key=$2 +ISO_DAYS=30 +TODAY=`date +%s` +files=`ssh -i $my_key -o StrictHostKeyChecking=no root@121.36.84.172 "ls $DIR | grep openeuler-"` + +for file in $files +do + echo $file + if [[ $file == openeuler-* ]];then + year=`echo $file | cut -d "-" -f 2` + month=`echo $file | cut -d "-" -f 3` + day=`echo $file | cut -d "-" -f 4` + hour=`echo $file | cut -d "-" -f 5` + if [[ -z $hour ]];then + echo "don't delete $DIR/$file, check next" + continue + fi + file=`echo $file | sed 's/\r//g'` + echo "$file +++++++" + date=`date +%s -d "$year-$month-$day"` + if [ `expr $TODAY - $date` -gt `expr $ISO_DAYS \* 24 \* 3600` ];then + if [[ "x$file" != "x*" ]];then + echo "delete directory $DIR/$file" + ssh -i $my_key -o StrictHostKeyChecking=no root@121.36.84.172 "cd $DIR && rm -rf $file" + fi + else + echo "don't delete $DIR/$file" + fi + fi +done + +echo "--------------- end delete older iso ----------------" -- Gitee