Passing awk through ssh help

First off we have hundreds of webservers in our farm that we sometimes have to collect logs for customers. Thing is the script that I currently am working on doesnt like my awk commands via ssh. I am very novice at best so all help would be greatly appreciated.

ssh a$active "awk '{if("$8"=='"$src"'&&"$1"==""$date""&&"$6"==""$coserver"")print}' /cdn/logs/FP/stale/request*"

I have some variables that are defined earlier in the script but what happens is it wont pass the columns in the awk statment. Any ideas?

Thanks
Greg

Did you try to use local variable remotely :rolleyes:

Again I am very novice and dont know what you mean here.

not tested - YMMV:

ssh a$active "awk '$8==s && $1==d && $6==c' s=${src} d=${date} c=${coserver} /cdn/logs/FP/stale/request*"
ssh a$active "awk '{if($8 == $src && $1 == $date && $6 == $coserver )print}' /cdn/logs/FP/stale/request*"

I am getting syntax errors with that both:

ssh a$active "awk '{if($8 == $src && $1 == $date && $6 == $coserver )print}' /cdn/logs/FP/stale/request2028201-1253652816000.txt"

awk: {if( == 67.xxx.xxx.xxx && == 2009-09-22 && == 1300 )print}
awk: ^ syntax error
awk: {if( == 67.xxx.xxx.xxx && == 2009-09-22 && == 1300 )print}
awk: ^ syntax error
awk: {if( == 67.xxx.xxx.xxx && == 2009-09-22 && == 1300 )print}
awk: ^ syntax error

ssh a$active "awk '$8==s && $1==d && $6==c' s=${src} d=${date} c=${coserver} /cdn/logs/FP/stale/request2028201-1253652816000.txt"

awk: ==s && ==d && ==c
awk: ^ syntax error

I have no clue what to try.

Start by escaping your single quotes... and see if that helps.

ssh a$active "awk \'{if($8 == $src && $1 == $date && $6 == $coserver )print}\' /cdn/logs/FP/stale/request2028201-1253652816000.txt"

What is wrong with that?

ksh: syntax error at line 1: `(' unexpected

If $8, $1, and $6 are awk variables, escape the dollar signs.

Also quote the literals.

ssh a$active "awk '{if ( \$8 == \"$src\" && \$1 == \"$date\" && \$6 == \"$coserver\" )print}' /cdn/logs/FP/stale/request2028201-1253652816000.txt"

Or:

ssh a$active "awk -v s=\"$src\" -v d=\"$date\" -v c=\"$coserver\" '{if ( \$8 == s && \$1 == d && \$6 == c )print}' /cdn/logs/FP/stale/request2028201-1253652816000.txt"

Why dont you build you command seperatly and then execute it ...

CMD2SHOOT="AWK BLA BLA...." <--- this is where you include all the command
take care of double quotes and single quotes ... then ssh

ssh a$server $CMD2SHOOT

incase of doubt ... do a echo $CMD2SHOOT ... may be helpful to get more ...