views:

370

answers:

2

I run this bash command to display contents of somefile.cf in a Weblogic domain directory.

find $(/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed -e 's/weblogic.policy//' -e 's/security\///' -e 's/dep\///' | awk -F'/' '{print "/"$2"/"$3"/"$4"/somefile.cf"}' | sort | uniq) 2> /dev/null -exec ls {} \; -exec cat {} \;

I tried incorporating this in an expect script and also escaped some special characters and double quotes too but it throws an error "extra characters after close-quote"

send "echo ; echo 'Weblogic somefile.cf:' ; find \$(/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print \$2}' | sed -e 's/weblogic.policy//' -e 's/security\\///' -e 's/dep\\///' | awk -F'/' '{print \"/\"\$2\"/\"\$3\"/\"\$4\"/somefile.cf\"}' | sort | uniq) 2> /dev/null -exec ls {} \\; -exec cat {} \\;

I guess it needs some more escaping of special characters or probably I dint escape the existing ones correctly. Any help would be appreciated.

A: 

give us the syntax error find or bash threw on the other side. and try adding an extra \ or 2 before the semicolons at the end.

The problem with expect is the number of layers of escapes you need when it get's ugly.

In the awk statement, go escape all the doublequotes ( " -> \" )

and get me an error message :)

Chris Hansen
I get this error when I run the line as is in my questionextra characters after close-quote while compiling"send "echo ; echo 'Weblogic somefile.cf:' ; find \$(/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print ..."
Sharjeel Sayed
Looks like a double quote without enough escapes.I'll slide it in to my test script if I have time, until then ...try:send "echo ; echo 'Weblogic somefile.cf:' ; find \$(/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print \$2}' | sed -e 's/weblogic.policy//' -e 's/security\\///' -e 's/dep\\///' | awk -F'/' '{print \"/\"\$2\"/\"\$3\"/\"\$4\"/somefile.cf\"}' | sort | uniq) 2> /dev/null -exec ls {} \\; -exec cat {} \\; ; echo\r"
Chris Hansen
does this part really have to be so long?| sed -e 's/weblogic.policy//' -e 's/security\\///' -e 's/dep\\///' |or could you do| sed 's/weblogic.policy//;s/security\\///;s/dep\\///' |
Chris Hansen
I tried escaping the double quotes but it still throws the same error "extra characters after close-quote"send "echo ; echo 'Weblogic somefile.cf:' ; find \$(/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print \$2}' | sed -e 's/weblogic.policy//' -e 's/security\\///' -e 's/dep\\///' | awk -F'/' '{print \"/\"\$2\"/\"\$3\"/\"\$4\"/somefile.cf\"}' | sort | uniq) 2> /dev/null -exec ls {} \\; -exec cat {} \\;
Sharjeel Sayed
A: 

If you have a command line with complex quoting that you know works in bash then it's often easier to just go ahead and use bash. Like this:

set cmd {find $(/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed -e 's/weblogic.policy//' -e 's/security\///' -e 's/dep\///' | awk -F'/' '{print "/"$2"/"$3"/"$4"/somefile.cf"}' | sort | uniq) 2> /dev/null -exec ls {} \; -exec cat {} \;}
spawn /bin/bash -c $cmd
expect ... whatever is appropriate ...

Notice that I used the Tcl {} operator instead of "" around the command string. This operator is like single quote in bash, it means "literal string, do not interpret the contents in any way" and is appropriate here because I want to pass this string verbatim to the spawned bash subprocess.

joefis