【4.8、4.9】ES会话索引清除脚本
!/bin/bash
a=$(date “+%Y-%m-%d” -d “10 days ago” |xargs date +%s -d) #将10天前的年-月-日格式转换成时间戳
echo a=$a
curl 192.168.8.70:9200/_cat/indices/meta-session* |awk ‘{print $3}’|awk -F ‘-‘ ‘{print $3″-“$4”-“$5}’>/tmp/1.txt #将meta-session索引最后的年-月-日截取并输入到1.txt文本
for LINE in $(</tmp/1.txt) #逐行读取1.txt
do
if [[ $(date +%s -d $LINE) -lt $a ]] #判断是否小于10天前的时间戳
then
curl -XDELETE 192.168.8.70:9200/meta-session-$LINE #删除小于10天前时间戳的索引
fi
done
脚步内容如上,是将10天前的meta-session进行删除,其它索引如需删除可以进行参考