#!/bin/sh ip=‘127.0.0.1‘ port=‘9200‘ day=`date -d "2 days ago" +%Y%m%d` #day=`date -d "5 hour ago" +%Y.%m.%d` echo "" echo "=================================================" echo `date +"%Y-%m-%d %H:%M.%S"` indexname=`curl -XGET -s $ip:$port/_cat/indices|awk ‘{print $3}‘` if [ $? -ne 0 ];then echo "Connect $ip:$port error...." else echo "Connect $ip:$port Sucess,loading index ..." fi length=${#indexname[@]} if [[ 0 -eq "$lenqth" ]];then echo "Nothings to do!" fi for i in $indexname do time=`echo $i|awk -F"-" ‘{print $NF}‘|egrep "([0-9][0-9][0-9][0-9]).(0[1-9]|[1][0-2]).(0[1-9]|[1-2][0-9]|3[0-1])"` time=${time//./} if [ -n "$time" ];then if [ "$time" -lt "$day" ];then echo "Delete $i" curl -XDELETE http://$ip:$port/$i fi fi done echo ""
以上脚本加入crontab
#每天清理es数据 0 1 * * * /data/shell/rm_esindex.sh >> /data/logs/rm_esindex.log
PS:
https://www.cnblogs.com/shiyiwen/p/8311014.html
https://www.cnblogs.com/yxwkf/p/5196016.html
原文地址:https://www.cnblogs.com/phpdragon/p/10182439.html
时间: 2024-10-27 14:24:12