shell脚本自动删除es索引脚本
#!/bin/bash
function delete_index() {
comp_date=`date -d "30 day ago" +"%Y-%m-%d"`
date1="$1 00:00:00"
date2="$comp_date 00:00:00"
t1=`date -d "$date1" +%s`
t2=`date -d "$date2" +%s`
if [ $t1 -le $t2 ]; then
format_date=`echo $1| sed 's/-/./g'`
curl -XDELETE http://xxxx:9200/smec-nginx-*$format_date
fi
}
curl -XGET http://xxxxx:9200/_cat/indices | awk -F" " '{print $3}' | awk -F"-" '{print $NF}' | egrep "[0-9]*.[0-9]*.[0-9]*" | sort | uniq | sed 's/./-/g' | while read LINE
do
delete_index $LINE
done