Monday, April 23, 2018

Restoring SQL queries from /var/log/asterisk/messages log-files.

One of customers had problem with Asterisk CEL due to insufficient HDD space left on Asterisk server. To extract SQL queries from messages, I used these sequence:
  1. cd /var/log/asterisk/
  2. grep "cel_odbc.c: Insert failed on" messages | awk '{$1=$2=$3=$4=$5=$6=$7=$8=$9=$10=$11=""; print $0}'  > messages_last
  3. removing all sequences of more than 1 white-spaces (previous command created 11 whitespace sequence):
    1. tr -s " " < messages_last > messages_truncated
  4. remove one white space left before INSERT statement:
    1. sed -i 's/^ *//' messages_truncated
  5. append ";" to the end of each line:
    1. sed -i 's/$/;/' messages_truncated
  6. execute queries from the file:
    1. mysql -u root -p asterisk
    2. SOURCE /var/log/asterisk/messages_truncated
    3. or
    4. mysql -u root -p asterisk < /var/log/asterisk/messages_truncated



No comments:

Post a Comment