1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| #!/bin/bash
function delete_indices() { 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 echo "$1時間早於$comp_date,進行索引刪除" format_date=`echo $1| sed 's/-/\./g'` curl -XDELETE http://localhost:9200/*$format_date fi }
curl -XGET http://localhost: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_indices $LINE done
|