I have a shell-script which extract details from a log file between two dates and executes a command on the output to generate some report. The log files are on different server and scripts are executed on different server. the Script looks like :
#!/bin/sh
time1=$1
time2=$2
echo `ssh -i key user@ip -yes cat file | awk '{if(substr($4,2)>="'$time1'" && substr($4,2)<="'$time2'") print $0;}'` > tmp.log
`cat tmp.log | some operation to get detail`
The output expected to be in multiple lines like :
ip1 date1 - - request1 file1 method1 status1
ip2 date2 - - request2 file2 method2 status2
But the output generated (by my command) is getting concatenated into a single line, containing all the details, like:
ip1 date1 - - request1 file1 method1 status1 ip2 date2 - - request2 file2 method2 status2
When the command is executed directly on the server it generates desired output but not when executed remotely.
So my question is how would I get the correct output and is this a good way to do it ?
echoin backticks is not only silly, but wrong. Simply replaceecho `whatever`withwhatever. See also porkmail.org/era/unix/award.html#echoecho "`command`"