Optimized query, support for edificio by `nombre' extraction.
[tarificador.git] / csv_gen.sh
blob21fb5c207a4d438326785cf5a8032eda2fce2f16
1 #!/bin/bash
2 # An script to generate a csv.
3 DEBUG='echo'
4 GET="/home/the00z/neuroservices/tarificador/get"
5 TMP=`getopt -o h --long help -- "$@"`
7 eval set -- "$TMP"
9 while true
11 case "$1" in
12 h|help)
13 echo "Ayuda."
14 exit 1
16 --)
17 shift
18 break
20 esac
21 done
23 if [ -z "$@" ]
24 then
25 echo "I need an argument at least to work"
28 for EDIFICIO in $@
31 eval 'time' "'$GET'" > "$EDIFICIO.csv" <<END
32 select
33 date(llamada.start), time(llamada.start),'','1.49', llamada.destino,
34 duration,concat('0',edificio_extension.edificio_id,extension.numero),'',
35 llamada.cuenta, ''
36 from
37 edificio, edificio_extension, extension , extension_llamada , llamada
38 where
39 edificio.id='${EDIFICIO}' and
40 edificio.id<=>edificio_extension.edificio_id and
41 edificio_extension.extension_id<=>extension.id and
42 extension.id<=>extension_llamada.extension_id and
43 extension_llamada.llamada_id<=>llamada.id
44 and llamada.d_context regexp '^(cs-|in|celu)'
45 and llamada.cuenta != ''
46 and llamada.disposition regexp '^answered'
47 and llamada.last_app regexp 'dial'
48 and llamada.d_context not regexp 'interno'
49 and llamada.bill_sec != '0'
50 and llamada.destino regexp '^9'
51 and extension.numero !=''
52 order
53 by llamada.start
54 END
56 if [ "$?" != "0" ]; then exit "$?";fi
57 done