#/bin/bash
#指定日期(3个月前)
DATA=`date -d "3 month ago" +%Y-%m-%d`
#当前日期
time=`date`
#删除3个月前的日志
curl -XDELETE http://127.0.0.1:9200/*-${DATA}
if [ $? -eq 0 ];then
echo $time"-->del $DATA log success.." >> /data/elk/logs/es-index-clear.log
else
echo $time"-->del $DATA log fail.." >> /tmp/es-index-clear.log
fi
Join crontab check the log three months before the day and delete
50 23 * * * /bin/bash /data/shell/es-index-clear.sh > /dev/null 2>&1
Delete the first index in December
curl -XDELETE http://localhost:9200/*-2017.12*