Created
April 6, 2016 11:50
-
-
Save amit-naudiyal/553dd057c5d97ae9c4bec0433ab0c0f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#This script is to get smaller Epoch values than the specified value in an Oplog dump. | |
#It assumes you have kept your readable dump at the same loction where this script is. | |
#author a.naudiyal | |
SED=`which sed` | |
JQ=`which jq` | |
UNIQ=`which uniq` | |
TR=`which tr` | |
CAT=`which cat` | |
GREP=`which grep` | |
PYTHON=`which python` | |
OPDIR=`pwd` | |
echo "Enter epoch value: " | |
read epochv | |
if [ ! -f $OPDIR/oplog.rs.json ];then | |
echo "oplog.rs.json file not found. Exiting..." | |
exit 1 | |
fi | |
$SED -i s/\$timestamp/timestamp/g oplog.rs.json | |
ARRAY=$($JQ '.ts.timestamp.t' <oplog.rs.json |$UNIQ |$TR "\n" ",";echo) | |
#Generate Python code and get the epoch value | |
$CAT <<EOF >/tmp/smaller.py | |
#!$PYTHON | |
import bisect | |
mylist = [$ARRAY] | |
mylist.sort() | |
f = open('Onesmaller', 'w') | |
index = bisect.bisect(mylist, $epochv) | |
print>>f, mylist[index-1] | |
f.close() | |
EOF | |
# Find ordinal numbers for the epoch value | |
cd /tmp | |
chmod 755 smaller.py | |
$PYTHON smaller.py | |
EPOCHVAL=`cat /tmp/Onesmaller` | |
clear | |
echo "Final epoch value is $EPOCHVAL " | |
echo | |
echo "And the Ordinal numbers associated with this Epoch value is/are:" | |
echo | |
cd $OPDIR | |
$JQ '.ts.timestamp.t, .ts.timestamp.i' < oplog.rs.json |$GREP -w $EPOCHVAL -A1 | |
##Cleanup | |
rm -f /tmp/Onesmaller | |
rm -f /tmp/smaller.py | |
#end of script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment