Scheduled cdr reports with cronjob

You could run from cron:-

/bin/rm -rf /tmp/results.txt&&/usr/bin/mysql -u youruser -pyourpassword -D asteriskcdrdb -e “SELECT * INTO OUTFILE ‘/tmp/results.txt’ FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY '”’ LINES TERMINATED BY ‘\n’ FROM cdr WHERE calldate BETWEEN ‘$(date -d “$(date) -1 month” +%Y-%m-%d)’ AND ‘$(date +%Y-%m-%d)’"

the day after you want your stuff.

(notes:-

mysql can only write where it is allowed to, neither /tmp/ nor /var/lib/mysql/ is a great choice but it’s a good place to start . . . .

cron should run under a limited shell so fully qualify anything called by it

)