定時刪除10天的es索引腳本

定時shell腳本如下

ip='127.0.0.1'
port=9200
endUnixTime=`date -d "10 day ago" +%s`
indices=`curl -XGET "http://${ip}:${port}/_cat/indices" | awk '{print $3}'`
for index in ${indices[*]}
do
   indexTime=${index##*logs-}
   year=`echo ${indexTime} | cut -d "." -f1`
   month=`echo ${indexTime} | cut -d "." -f2`
   day=`echo ${indexTime} | cut -d "." -f3`

   if [ ! $year ]
      then
          echo "ignore index:$index"
          continue
   fi

   indexUnixTime=`date -d "$year$month$day" +%s`
   if [ $indexUnixTime -lt $endUnixTime ]
      then
         echo "Delete index:$index"
         curl -XDELETE "http://${ip}:${port}/$index"
   fi
done
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章