Monday, September 3, 2012

how we can import freeswitch cdr from master.cv to mysql using linux shell script

#!/bin/bash
host='192.168.1.105'
user='dbuser'
password='dbpassword'
DB='livecalls'
cat /usr/local/freeswitch/log/cdr-csv/Master.csv >> /usr/local/freeswitch/log/cdr-csv/Full_CDR_Log.csv
mastercsvfile='/usr/local/freeswitch/log/cdr-csv/Master.csv'
if [[ -s $mastercsvfile ]] ; then
    /usr/local/bin/fs_cli -x 'cdr_csv rotate'
else
echo "$FILE is empty."
fi ;
NOW=$(date +"%Y-%m-%d-%H-%M")
file=$(ls  /usr/local/freeswitch/log/cdr-csv |grep Master.csv.$NOW)
#echo $file
FILE=/usr/local/freeswitch/log/cdr-csv/$file
if [[ -s $FILE ]] ; then
mysql -h $host -u$user -p$password  $DB < /usr/local/freeswitch/log/cdr-csv/$file
rm -rf  /usr/local/freeswitch/log/cdr-csv/$file
else
echo "$FILE is empty."
rm -rf  /usr/local/freeswitch/log/cdr-csv/$file
fi ;
Note:
Make a file with .sh extension and add is file in crontab for auto execution.

2 comments:

  1. It`s really works?
    mysql -h $host -u$user -p$password $DB < /usr/local/freeswitch/log/cdr-csv/$file

    ReplyDelete
  2. but there is another way which more effective than this method

    ReplyDelete