Skip to content

Instantly share code, notes, and snippets.

@markuskont
Last active April 28, 2016 08:17
Show Gist options
  • Save markuskont/2484ce30f548794b72ebbb9648558457 to your computer and use it in GitHub Desktop.
Save markuskont/2484ce30f548794b72ebbb9648558457 to your computer and use it in GitHub Desktop.
Delete moloch session indices as per retention period in days when indices are created hourly. Very hacky and quick solution.
#!/bin/bash
RETAINDAYS=7
HOST="localhost"
PORT=9200
INDICES=`curl -ss -XGET $HOST:$PORT/_cat/indices?v | awk -F " " '{print $3}' | grep sessions | sort -n`
TODAY=`date +"%y%m%d"`
for index in $INDICES; do
DATE=`echo $index | perl -ne 'if (m/sessions-(\d+)h\d+/){print "$1\n"}'`
DIFF=$(($TODAY - $DATE))
if [ $DIFF -gt $RETAINDAYS ]
then
curl -XDELETE $HOST:$PORT/$index
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment