Skip to content

Instantly share code, notes, and snippets.

@maxclark
Created April 13, 2018 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxclark/47521ca735d844d6dd7c88e75c1cc588 to your computer and use it in GitHub Desktop.
Save maxclark/47521ca735d844d6dd7c88e75c1cc588 to your computer and use it in GitHub Desktop.
Simple script to rotate FreeSWITCH CDRs for our BSS platform
#!/bin/sh
SOURCE=/var/log/freeswitch/cdr-csv
PICKUP=/home/cdr/cdr
ARCHIVE=/home/cdr/archive
# Instructs FreeSWITCH to rotate the CDR file
#
#/bin/kill -HUP `cat /usr/local/freeswitch/run/freeswitch.pid`
/usr/bin/fs_cli -x 'cdr_csv rotate'
# Create the directories we need if they don't exist
#
if [ ! -d "${PICKUP}" ]; then
mkdir -p ${PICKUP}
fi
if [ ! -d "${ARCHIVE}" ]; then
mkdir -p "${ARCHIVE}"
fi
# ARCHIVE everything older than x days
#
#echo "find ${SOURCE} -name 'Master.csv.*' -ctime +60 -exec mv {} ${ARCHIVE} \;"
find ${SOURCE} -name 'Master.csv.*' -ctime +60 -exec mv {} ${ARCHIVE} \;
# Sync to the $PICKUP directory for remote retrieval
#
rsync -a --delete /var/log/freeswitch/cdr-csv/Master.csv.* /home/cdr/cdr/
# Make sure the files are readable
#
/bin/chmod 644 /home/cdr/cdr/Master.csv.*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment