Created
August 20, 2020 06:19
-
-
Save petrohs/3200d2b5f7258aa44711ab0f3e7561d1 to your computer and use it in GitHub Desktop.
buscaCdrDxl¦ Busca el cdr dentro de un archivo volcado dxl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
ayuda () { echo ' | |
#=============================================================================== | |
# | |
# SCRIPT: buscaCdrDxl.sh | |
# | |
# USO: buscaCdrDxl.sh [-i lista] [-d dir/dxls] [-s arch_sal] | |
# buscaCdrDxl.sh [-t tipo] [-D num] | |
# buscaCdrDxl.sh [-h|-?|--help] [-v|--version] | |
# | |
# DESCRIPCION: Busca el cdr dentro de un archivo volcado dxl | |
# | |
# OPCIONES: -i lista Listado de valores a buscar. Por omision es | |
# /tmp/buscaCdrsDxl/imsis.lista | |
# -d dir/dxls Directorios donde estan los volcados dxl. Por | |
# omision es /tmp/buscaCdrsDxl/dxls/ | |
# -s arch_sal Nombre del archivo de salida. Por omision es | |
# /tmp/buscaCdrsDxl/detalle_DataPos_*.dxl | |
# -t tipo Tipo de registro: 10 dna. 11 imsi. Por omision | |
# es 11 | |
# -D num Nivel de debug: 0, 1, 2, 3, 4. Por omision 0 | |
# sin info | |
# -v Version | |
# -h Ayuda | |
# DEPENDENCIAS: --- | |
# BUGS: --- | |
# NOTAS: Antes buscaImsiDxl.sh | |
# VERSIONES: 20161130 0.0.4 petrohs Argumentos | |
# 20161129 0.0.3 petrohs De buscar imsi a cdrs | |
# 20160829 0.0.2 petrohs Ajustes | |
# URL: --- | |
#===============================================================================' | more;} | |
#ayuda | |
if [ "$1" = "" -o "$1" = "-h" -o "$1" = "--help" ]; then ayuda; exit 1; | |
elif [ "$1" = "-v" -o "$1" = "--version" ]; then ayuda | grep "# VERSIONES:" | cut -d\: -f2-; exit 1; | |
fi | |
pLog=$(echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | iniciando proceso"); | |
#iniciando variables | |
archivoImsis="/tmp/buscaCdrsDxl/imsis.lista"; | |
directorioDxl="/tmp/buscaCdrsDxl/dxls"; | |
directorioSal="/tmp/buscaCdrsDxl"; | |
tipo=11; | |
debug=0; | |
#opciones | |
pLog2=$(echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | leyendo opciones"); | |
while getopts i:d:s:t:D: _opciones | |
do | |
case "$_opciones" in | |
i) | |
archivoImsis="$OPTARG"; | |
;; | |
d) | |
directorioDxl="$OPTARG"; | |
;; | |
s) | |
archivoSal="$OPTARG"; | |
directorioSal="`dirname ${archivoSal}`"; | |
;; | |
t) | |
tipo="$OPTARG"; | |
;; | |
D) | |
debug="$OPTARG"; | |
[ $debug -eq 4 ] && set -x; | |
;; | |
esac | |
done | |
shift `expr $OPTIND - 1` | |
#validaciones | |
[ $debug -gt 0 ] && echo "$pLog" ; | |
[ $debug -gt 1 ] && echo "$pLog2" ; | |
[ $debug -gt 1 ] && echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | validaciones" ; | |
if [ ! -r "$archivoImsis" ]; then echo "'$archivoImsis' No es un archivo valido"; exit 1; fi; | |
if [ ! -s "$archivoImsis" ]; then echo "'$archivoImsis' No es un archivo valido"; exit 1; fi; | |
if [ ! -d "$directorioDxl" ]; then echo "'$directorioDxl' No es un directorio valido"; exit 1; fi; | |
if [ ! -d "$directorioSal" ]; then echo "'$directorioSal' No es un directorio valido"; exit 1; fi; | |
archivoImsis2="${archivoImsis}.tmp2" | |
archivoImsis3="${archivoImsis}.tmp3" | |
archivoSal="$directorioSal/detalle_DataPos_`date +%Y%m%d%H%M%S`_`echo $RANDOM`.dxl"; | |
cdrIni="BSCSUDR:"; | |
cdrFin="-----------------------------------------------------------------------------------"; | |
if [ $debug -gt 2 ] | |
then | |
echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | archivoImsis: -$archivoImsis-" ; | |
echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | directorioDxl: -$directorioDxl-" ; | |
echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | directorioSal: -$directorioSal-" ; | |
echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | archivoSal: -$archivoSal-" ; | |
echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | archivoImsis2: -$archivoImsis2-" ; | |
echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | archivoImsis3: -$archivoImsis3-" ; | |
echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | tipo: -$tipo-" ; | |
fi | |
#Generar la busqueda | |
[ $debug -gt 1 ] && echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | formando la cadena" ; | |
cat $archivoImsis | sed -e "s/.*/field_id=${tipo}, attr_id=9, value(String)=\"&/" > $archivoImsis2 | |
[ $debug -gt 2 ] && echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | la cadena:" && (cat $archivoImsis2 | sed -e "s/.*/ &/") ; | |
[ $debug -gt 1 ] && echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | busqueda" ; | |
grep -n -f $archivoImsis2 $directorioDxl/* > $archivoImsis3 | |
[ $debug -gt 2 ] && echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | la busqueda:" && (cat $archivoImsis3 | sed -e "s/.*/ &/") ; | |
#Localizar las lineas | |
[ $debug -gt 1 ] && echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | obtener cdr" ; | |
for linea in `cat $archivoImsis3 | tr " " "_"` | |
do | |
[ $debug -gt 2 ] && echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | linea -$linea-" ; | |
archivoUbicado=`echo "$linea" | cut -d: -f1`; | |
lineaUbicada=`echo "$linea" | cut -d: -f2`; | |
imsiUbicada=`echo "$linea" | cut -d= -f4`; | |
lineaInicial="xxx" | |
lineaNinicial=$lineaUbicada; | |
while [ "$lineaInicial" != ${cdrIni} ] | |
do | |
lineaNinicial=`expr $lineaNinicial - 1` | |
lineaInicial="`sed -n ${lineaNinicial}p $archivoUbicado`" | |
done | |
sed -n ${lineaNinicial},${lineaUbicada}p $archivoUbicado >> $archivoSal | |
lineaFinal="xxx" | |
lineaNfinal=$lineaUbicada; | |
while [ "$lineaFinal" != ${cdrFin} ] | |
do | |
lineaNfinal=`expr $lineaNfinal + 1` | |
lineaFinal="`sed -n ${lineaNfinal}p $archivoUbicado`" | |
echo "$lineaFinal" >> $archivoSal | |
done | |
done | |
# | |
[ $debug -gt 0 ] && echo "buscaCdrDxl.sh | `date +%Y%m%d_%H%M%S.%N` | termina proceso" ; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment