您的当前位置:首页正文

自动删除 Elasticsearch 索引

2024-11-10 来源:个人技术集锦
#!/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

转载于:https://www.cnblogs.com/wangxiaoqiangs/p/6126729.html

显示全文