Advertisement
soapee01

yesterday's inbound cdrs with the DID

Feb 10th, 2017
179
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. YESTERDAY=$(date --date="yesterday" +%Y-%m-%d)
  4. TODAY=$(date +%Y-%m-%d)
  5. DATESTAMP=$(date +%Y%m%d%H%M%S)
  6. EMAIL_RECIP="you@net.com"
  7.  
  8. #adjust for your timezone
  9. date |grep CST > /dev/null
  10. if [ $? -eq 0 ]; then
  11.         TZ="-06"
  12. else
  13.         TZ="-05"
  14. fi
  15.  
  16. 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
  17.  
  18. 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
  19.  
  20. rm /tmp/cdrdids-$DATESTAMP.csv
Advertisement
RAW Paste Data Copied
Advertisement