Created
April 10, 2016 20:01
-
-
Save Sleavely/7d087e13410d01ebf1e6689719e95372 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 | |
# Change the server address. Run in the /logs/ directory. | |
apihost="http://api.localhost"; | |
logfile=$(ls -tr xmpp_* | tail -1); | |
# Dont edit below this line :) | |
vcard=""; | |
# Using awk to flush every line separately to avoid buffering issues. I think. | |
tail -f "$logfile" | awk '{print $0; fflush()}' | while read -r line | |
do | |
linecopy=$line; | |
presencestr="presence from=\"global"; | |
nickstr="\<NICKNAME"; | |
nationstr="\<NATION"; | |
clanstr="\<CLAN"; | |
if [[ $linecopy == *$presencestr* ]] | |
then | |
curl -d "data=${linecopy}" "$apihost/chat-parser/presence"; | |
elif [[ $linecopy == *$nickstr* ]] | |
then | |
vcard="$vcard$linecopy"; | |
elif [[ $linecopy == *$nationstr* ]] | |
then | |
vcard=$vcard$linecopy; | |
elif [[ $linecopy == *$clanstr* ]] | |
then | |
vcard="$vcard$linecopy"; | |
fi | |
# Look for finished vcard | |
if [[ $vcard == *$nickstr* ]] | |
then | |
if [[ $vcard == *$nationstr* ]] | |
then | |
if [[ $vcard == *$clanstr* ]] | |
then | |
vcard="<vcard>$vcard</vcard>"; | |
curl -d "data=${vcard}" "$apihost/chat-parser/vcard"; | |
vcard=""; | |
fi | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment