不带账号密码
#!/bin/bash source /etc/profile #定义删除30天以前的函数 delete_indices(){ check_day=`date -d '-30 days' '+%F'` index_day=$1 #将日期转换为时间戳 check_day_timestamp=`date -d "$check_day" +%s` index_day_timestamp=`date -d "$index_day" +%s` #当索引的时间戳值小于当前日期30天前的时间戳时,删除此索引 if [ ${index_day_timestamp} -lt ${check_day_timestamp} ];then #转换日期格式 format_date=`echo $1 | sed 's/-/\./g'` curl -XDELETE http://39.97.226.254:9200/*$format_date fi } curl -XGET http://39.97.226.254:9200/_cat/indices | awk -F" " '{print $3}' | awk -F"-" '{print $NF}' | egrep "[0-9]*\.[0-9]*\.[0-9]*" | sort | uniq | sed 's/\./-/g' | while read LINE do #调用索引删除函数 delete_indices $LINE done
带账号和密码
#!/bin/bash source /etc/profile delete_indices(){ check_day=`date -d '-10 days' '+%F'` index_day=$1 check_day_timestamp=`date -d "$check_day" +%s` index_day_timestamp=`date -d "$index_day" +%s` if [ ${index_day_timestamp} -lt ${check_day_timestamp} ];then format_date=`echo $1 | sed 's/-/\./g'` curl -XDELETE -u elastic:inGDWRU!wS1EQJAL#2D4djpuy!AdB03xK http://127.0.0.1:9200/*$format_date fi } curl -XGET -u elastic:inGDWRU!wS1EQJAL#2D4djpuy!AdB03xK http://127.0.0.1:9200/_cat/indices | awk -F" " '{print $3}' | awk -F"-" '{print $NF}' | egrep "[0-9]*\.[0-9]*\.[0-9]*" | sort | uniq | sed 's/\./-/g' | while read LINE do delete_indices $LINE done
继续阅读
评论