Skip to content

Instantly share code, notes, and snippets.

@xenithorb
Created April 19, 2017 14:51
Show Gist options
  • Save xenithorb/f428aa893abbfa62a9b3325f659c0a87 to your computer and use it in GitHub Desktop.
Save xenithorb/f428aa893abbfa62a9b3325f659c0a87 to your computer and use it in GitHub Desktop.
Parse freeswitch log for DTMF codes and output a single string
#!/bin/bash
LOGFILE="/var/log/freeswitch/freeswitch.log*"
#LOGFILE="/usr/local/freeswitch/log/freeswitch.log*"
USER="centos"
REMOTE_ADDR="${1:?ERROR: No remote address provided}"
UUID="${2:?ERROR: No UUID provided}"
get_logs() {
"$SUDO" find "${LOGFILE%/*}" -type f -name "${LOGFILE##*/}" ! -empty
}
dtmf_extract() {
awk -F'[: ]' 'BEGIN{ ORS="" } /RTP RECV DTMF/ && /'$UUID'/ { print $12 }'
}
ssh -qtt "${USER}@${REMOTE_ADDR}" \
"
# set -x;
LOGFILE=\"$LOGFILE\";
UUID=\"$UUID\";
SUDO=\"\$(command -v sudo)\";
$(typeset -f dtmf_extract get_logs);
\$SUDO zcat -f \$(get_logs) | dtmf_extract;
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment