Skip to content

Instantly share code, notes, and snippets.

@XUJiahua
Created September 18, 2017 03:20
Show Gist options
  • Save XUJiahua/48bdc8687500958733aa4c3049c831cd to your computer and use it in GitHub Desktop.
Save XUJiahua/48bdc8687500958733aa4c3049c831cd to your computer and use it in GitHub Desktop.
ElasticSearch数据清理(保留90天)
from datetime import datetime
from time import mktime
import time
import sys
for line in sys.stdin:
try:
datestr =line.strip()[-10:]
dt = time.strptime(datestr, "%Y.%m.%d")
dt = datetime.fromtimestamp(mktime(dt))
if (datetime.now() - dt).days > 90:
print line.strip()
except:
x = 1
#!/bin/bash
curl http://10.171.255.144:9200/_cat/indices | awk '{print $3 }' | python filter_log_before_3_month.py | awk '{print "-X DELETE http://10.171.255.144:9200/"$0}' | xargs curl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment