自动删除 Elasticsearch 索引

#!/bin/bash
# author: Wang XiaoQiang
# crontab -e
# 0 0 * * * /root/script/del_esindex.sh # auto delete
7 day ago elasticsearch index dtime=`date -d "7 day ago" +%Y-%m-%d` dtime_stamp=`date -d "$dtime" +%s` indexs=`curl -s 'http://127.0.0.1:9200/_cat/indices' | awk '$3~/^logstash/{print $3}'` for line in $indexs;do index=$line itime=`echo $line | awk -F - '{print $3}' | tr '.' '-'` itime_stamp=`date -d "$itime" +%s` if [ $itime_stamp -lt $dtime_stamp ];then curl -X DELETE "http://127.0.0.1:9200/$index" > /dev/null 2>&1 fi done
posted @ 2016-12-02 17:53  WangXiaoQiang  阅读(1745)  评论(0编辑  收藏  举报