http://127.0.0.1:9200/_cat/indices?v
#!/bin/bash
#删除ELK30天前的日志
DATE=`date -d "30 days ago" +%Y.%m.%d`
curl -s -XGET http://127.0.0.1:9200/_cat/indices?v| grep $DATE | awk -F '[ ]+' '{print $3}' >/tmp/elk.log
for elk in `cat /tmp/elk.log`
do
curl -XDELETE "http://127.0.0.1:9200/$elk"
done
二:加入到定时任务
# crontab -e
#每天凌晨1点定时清理elk索引
00 01 * * * bash /server/scripts/elk.sh &>/dev/null
注意:保证crond服务是启动的
[root@server scripts]# service crond status
crond (pid 1999) is running...
网友评论