Skip to content

Instantly share code, notes, and snippets.

@Sleavely
Created April 10, 2016 20:01
Show Gist options
  • Save Sleavely/7d087e13410d01ebf1e6689719e95372 to your computer and use it in GitHub Desktop.
Save Sleavely/7d087e13410d01ebf1e6689719e95372 to your computer and use it in GitHub Desktop.
#!/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