Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- YESTERDAY=$(date --date="yesterday" +%Y-%m-%d)
- TODAY=$(date +%Y-%m-%d)
- DATESTAMP=$(date +%Y%m%d%H%M%S)
- EMAIL_RECIP="[email protected]"
- #adjust for your timezone
- date |grep CST > /dev/null
- if [ $? -eq 0 ]; then
- TZ="-06"
- else
- TZ="-05"
- fi
- psql -d fusionpbx -c "COPY ( SELECT json->'variables'->>'sip_req_user' as Dialed_Number,answer_stamp,end_stamp,duration,direction, context,caller_id_name,caller_id_number,destination_number,last_app,last_arg,cc_queue_joined_epoch,cc_queue,cc_agent,waitsec,hangup_cause,sip_hangup_disposition FROM v_xml_cdr WHERE start_epoch >= EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '$YESTERDAY 00:00:00$TZ') AND start_epoch <= EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '$TODAY 00:00:00$TZ') AND direction <> 'outbound' AND length(json->'variables'->>'sip_req_user') > 7 ) TO STDOUT WITH CSV HEADER " > /tmp/cdrdids-$DATESTAMP.csv
- echo "Attached is a CSV file that contains your inbound call detail records for $YESTERDAY, including the DID number that was called. Please note, the time stamps are adjusted for Central Time." | mail -s "DID CDR $YESTERDAY" -a /tmp/cdrdids-$DATESTAMP.csv -r support@net.com $EMAIL_RECIP
- rm /tmp/cdrdids-$DATESTAMP.csv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement