cut - Bash script builds correct $cmd but fails to execute complex stream -


this short script scrapes log files daily create simple extract. works command line , when echo $cmd , copy/paste, works. breaks when try execute script itself.

i know nightmare of patterns improve, missing simple execute correctly?

#!/bin/bash priorday=$(date --date yesterday +"%y-%m-%d") outputfile="/home/cchcs/da14/$priorday""_prod_message_processing_times.txt" cmd="grep 'processed inbound' /home/rules/care/logs/rootlog* | cut -f5,6,12,16,18 -d\" \" | grep '^"$priorday"' | sed 's/\,/\./' | sed 's/ /\t/g' | sed -r 's/([0-9]+\-[0-9]+\-[0-9]+)\t/\1 /' | sed 's/  / /g' | sort >$outputfile" printf "command execute:\n" echo $cmd printf "\n" $cmd 

ouput:

./make_log_extract.sh command execute: grep 'processed inbound' /home/rules/care/logs/rootlog.log /home/rules/care/logs/rootlog.log.1 /home/rules/care/logs/rootlog.log.10 /home/rules/care/logs/rootlog.log.11 /home/rules/care/logs/rootlog.log.12 /home/rules/care/logs/rootlog.log.2 /home/rules/care/logs/rootlog.log.3 /home/rules/care/logs/rootlog.log.4 /home/rules/care/logs/rootlog.log.5 /home/rules/care/logs/rootlog.log.6 /home/rules/care/logs/rootlog.log.7 /home/rules/care/logs/rootlog.log.8 /home/rules/care/logs/rootlog.log.9 | cut -f5,6,12,16,18 -d" " | grep '^2014-01-30' | sed 's/\,/./' | sed 's/ /\t/g' | sed -r 's/([0-9]+-[0-9]+-[0-9]+)\t/\1 /' | sed 's/ / /g' | sort /home/cchcs/da14/2014-01-30_prod_message_processing_times.txt

grep: 5,6,12,16,18: no such file or directory

as grebneke comments, not store command , execute it.

what can execute firstly print it: bash: print each command before executing?

priorday=$(date --date yesterday +"%y-%m-%d") outputfile="/home/cchcs/da14/$priorday""_prod_message_processing_times.txt"  set -o xtrace # <-- set printing mode "on" grep 'processed inbound' /home/rules/care/logs/rootlog* | cut -f5,6,12,16,18 -d\" \" | grep '^"$priorday"' | sed 's/\,/\./' | sed 's/ /\t/g' | sed -r 's/([0-9]+\-[0-9]+\-[0-9]+)\t/\1 /' | sed 's/  / /g' | sort >$outputfile" set +o xtrace # <-- revert normal 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -