#!/bin/sh
es_cluster="http://10.110.106.49:9200"
index_name="hadoop-sfbdp1-auditlog"
sys_date=`date '+%Y-%m-%d'`
event_date=`date -d "${sys_date} -15 day" +"%Y-%m-%d"`
cmd_cat="curl $es_cluster/_cat/indices?v | grep $event_date | grep $index_name| awk '{print \$3}'"
echo "开始获取集群中的索引名......"
index_to_delete=`eval $cmd_cat`
if [ -n "$index_to_delete" ]; then
cmd_delete="curl -XDELETE $es_cluster/$index_to_delete?pretty"
echo $cmd_delete
echo "开始删除索引..............."
eval $cmd_delete
if [ $? = 0 ]; then
echo "索引删除成功.............."
else
echo "索引删除失败.............."
fi
else
echo "索引不存在"
fi