Skip to content

Instantly share code, notes, and snippets.

@franzramadhan
Created March 12, 2018 06:18
Show Gist options
  • Save franzramadhan/d31758712736cba16f7b37f9066b6d48 to your computer and use it in GitHub Desktop.
Save franzramadhan/d31758712736cba16f7b37f9066b6d48 to your computer and use it in GitHub Desktop.
Rotate ELS index
#!/bin/bash
getIndices=$(curl -s "http://127.0.0.1:9200/_cat/indices?v" | awk '/'filebeat'/{match($0, /[:blank]*('filebeat'.[^ ]+)[:blank]*/, m); print m[1];}' | awk -F "-" '{print $2}')
now=$(date +%s)
for i in $getIndices;
do
converttoTime=$(echo $i|tr . -)
result=$((($now - $(date -d "$converttoTime" +%s))/(24 * 60 * 60)))
if [ $result -gt 7 ];
then
echo "Delete indices filebeat-$i"
curl -XDELETE http://127.0.0.1:9200/filebeat-$i
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment