elasticsearch定时删除索引第二版

该版本对于上一个版本做了升级。兼容性更好了。

#!/bin/bash
#######################################################
# $Name:        clean_index.sh
# $Version:     v2.0
# $Function:    delete es index
# $Author:      dongjiaxiao
# $Create Date: 2019-12-31
# $Description: shell
######################################################
#脚本的日志文件路径
CLEAN_LOG="/home/djx/scripts/clean_index.log"
#es地址
SERVER_PORT=172.17.1.212:9200
#保留的时间,单位天
DELTIME=45
SECONDS=$(date -d  "$(date  +%F) -${DELTIME} days" +%s)
INDEXS=$(curl -s -u  elastic:changeme  "${SERVER_PORT}/_cat/indices?v"|awk '{print $3}')
echo "-------------------$(date +%F_%T)---------------"  >>${CLEAN_LOG}
for del_index in ${INDEXS}
do 
     timeString=$( echo ${del_index} |awk -F"-" '{print $NF}'|egrep "[0-9]*\.[0-9]*\.[0-9]*")
     if [ -n "$timeString" ]
     then
         indexDate=${timeString//./-}
         indexSecond=$( date -d ${indexDate} +%s )
         if [ $(( $SECONDS- $indexSecond )) -gt 0 ]
         then
             delResult=`curl -s -u elastic:changeme  -XDELETE "${SERVER_PORT}/"${del_index}"?pretty" |sed -n '2p'`
             echo "delete index:$del_index result:$delResult" >>${CLEAN_LOG}
         fi
     fi
     
done 
上一篇:香洲区翠香街道哪条街有一条龙全套服务特殊大保健sdf


下一篇:利用JQuery获取事件源点击表格内加减号实现添加删除一行输入框