Shorten a sed command - using it to make asterisk call logs -
i know asterisk creates it's own phone call logs in form of csv file. purposes need phone call logs formatted have depicted below. use:
ls -l /var/spool/asterisk/monitor
basis phone call logs, produces this:
-rw------- 1 asterisk asterisk 112684 2013-02-07 17:24 20130207-172424-+15551235566-in.wav -rw------- 1 asterisk asterisk 44 2013-02-07 17:53 20130207-175311-+15554561122-in.wav -rw------- 1 asterisk asterisk 2019564 2013-02-07 18:00 20130207-175828-15554561122-out.wav -rw------- 1 asterisk asterisk 44 2013-02-07 22:09 20130207-220805-15554561122-out.wav -rw------- 1 asterisk asterisk 44 2013-02-07 22:12 20130207-221204-15551235566-out.wav -rw------- 1 asterisk asterisk 111084 2013-02-07 22:13 20130207-221255-15551235566-out.wav -rw------- 1 asterisk asterisk 364844 2013-02-07 22:39 20130207-223843-15558271212-out.wav -rw------- 1 asterisk asterisk 4279404 2013-02-07 23:53 20130207-234836-5552785454-out.wav -rw------- 1 asterisk asterisk 44 2013-02-08 00:00 20130208-000026-+15559813232-in.wav
the part need help command below. works , produces exact results want; however, seems bulky me. can shortened?
variables
yester=$(date -d "-24 hours" +"%y-%m-%d-%h%m") today=$(date +"%y-%m-%d-%h%m_utc")
create phone call log (command i'd change)
ls -l /var/spool/asterisk/monitor/ |grep '\.wav'|awk '{print $8 " " $5/1000000}'|sed -e 's/4\.4e\-05/not recorded/g' -e 's/\.wav//g' -e 's/-/ /g' -e 's/out/out - approx minutes:/g' -e 's/in/in - approx minutes:/g' -e 's/\(\.[0-9]\).*$/\1/g' -e 's/^.\{15\}/& utc -/' -e 's/^.\{13\}/&:/' -e 's/^.\{11\}/&:/' -e 's/^.\{6\}/&-/' -e 's/^.\{4\}/& /' -e 's/+//g' > /var/spool/asterisk/monitor/call_logs/${yester}__${today}-call-log.txt
for readability here command separated line (without | ):
ls -l /var/spool/asterisk/monitor/ grep '\.wav' awk '{print $8 " " $5/1000000}' sed -e 's/4\.4e\-05/not recorded/g' -e 's/\.wav//g' -e 's/-/ /g' -e 's/out/out - approx minutes:/g' -e 's/in/in - approx minutes:/g' -e 's/\(\.[0-9]\).*$/\1/g' -e 's/^.\{15\}/& utc -/' -e 's/^.\{13\}/&:/' -e 's/^.\{11\}/&:/' -e 's/^.\{6\}/&-/' -e 's/^.\{4\}/& /' -e 's/+//g' > /var/spool/asterisk/monitor/call_logs/${yester}__${today}-call-log.txt
output:
2013 02-07 17:24:24 utc - 15551235566 in - approx minutes: 0.1 2013 02-07 17:53:11 utc - 15554561122 in - approx minutes: not recorded 2013 02-07 17:58:28 utc - 15554561122 out - approx minutes: 2.0 2013 02-07 22:08:05 utc - 15554561122 out - approx minutes: not recorded 2013 02-07 22:12:04 utc - 15551235566 out - approx minutes: not recorded 2013 02-07 22:12:55 utc - 15551235566 out - approx minutes: 0.1 2013 02-07 22:38:43 utc - 15558271212 out - approx minutes: 0.3 2013 02-07 23:48:36 utc - 5552785454 out - approx minutes: 4.2 2013 02-08 00:00:26 utc - 15559813232 in - approx minutes: not recorded
you can set formating awk, why utilize sed?
to got simple, utilize
[root@gleb monitor]# ls -l --time-style="+%y-%m-%d %h:%m -" -rw-r--r-- 1 asterisk asterisk 5195 2013-01-09 21:42 - 20130109-214242-1357756962.1658.wav -rw-r--r-- 1 asterisk asterisk 13450 2013-01-13 22:33 - 20130113-223350-1358105630.4124.wav
unfortanly can't give total script, becuase have other files. based on such ls command output not need rewrite data, can utilize column. can total features processing including formating in single awk expression. http://www.gnu.org/software/gawk/manual/html_node/printf-examples.html
sed asterisk
No comments:
Post a Comment