I made this bash one-liner which I use to list Weblogic instances running along with their full paths.This works well when I run it from the shell.
/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed 's/weblogic.policy//' | sed 's/security\///' | sort
I tried to incorporate this in an expect script
send "echo Weblogic Processes: ; /usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print \$2}' | sed 's/weblogic.policy//' | sed 's/security\///' | sort ; echo ; echo\r"
but I got this error sed: -e expression #1, char 13: unknown option to `s'
Please help
you can try removing the single quotes and run the command again.
Its most probably quoting issues. If its not ok, try the suggestion by
hlovdal
meanwhile, some of your longish commands can be combined
Without careful counting or testing, I'd try adding another
\
after "security\", or possibly deleting the existing one.Also, you can combine the two seds into one:
sed -e 's/weblogic.policy//' -e 's/security\///'
I think this is too complex to send over to a remote host. Instead, put the commands in a small shell script and execute that. This way, you won't run into trouble because of quote expansion rules, escaping, etc.
Moreover, you should use
ssh
instead ofexpect
to run scripts.expect
is for running interactive commands likeftp
which don't have suitable scripting abilities.Use Tcl's {} operator instead of double quotes around the string you want to send. The {} syntax in Tcl is equivalent to single quote in bash, meaning "literal string, do not interpret its contents".
Inside the {} put exactly what you want Tcl/Expect to send to the subprocess, character for character, no extra quoting required.
Probably the
\
character inneeds an extra escape in expect context, e.g.