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