0

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 ?

3
  • The echo in backticks is not only silly, but wrong. Simply replace echo `whatever` with whatever. See also porkmail.org/era/unix/award.html#echo Commented Feb 23, 2015 at 9:18
  • Removing backticks is not producing any output. Commented Feb 23, 2015 at 9:31
  • Thank you I got it backticks neglects \n. so what I did is added the command inside " ".Like this : echo "`command`" Commented Feb 23, 2015 at 9:55

1 Answer 1

2

From your comments above you are still using "echo". @tripleee is correct. Don't. Also don't use the pointless cat at the start - simply redirect std in to your next command.

#!/bin/sh
time1=$1
time2=$2
ssh -i key  user@ip -yes cat file | awk '{if(substr($4,2)>="'$time1'" && substr($4,2)<="'$time2'") print $0;}' > tmp.log

some operation to get detail <tmp.log
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.