#!/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.
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.
It`s really works?
ReplyDeletemysql -h $host -u$user -p$password $DB < /usr/local/freeswitch/log/cdr-csv/$file
but there is another way which more effective than this method
ReplyDelete