Find 在 Expect Send 命令中不起作用
我运行此 bash 命令来显示 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 {} \;
我尝试将其合并到期望脚本中,并且也转义了一些特殊字符和双引号,但它会抛出错误“闭引号后的额外字符”
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
给我们 find 或 bash 在另一端抛出的语法错误。
并尝试在末尾的分号之前添加额外的 \ 或 2。
Expect 的问题在于当它变得丑陋时你需要的转义层数。
在 awk 语句中,转义所有双引号 ( " -> \" )
并给我一条错误消息:)
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 :)
如果您有一个带有复杂引用的命令行,并且您知道该命令行可以在 bash 中运行,那么直接使用 bash 通常会更容易。像这样:
请注意,我在命令字符串周围使用了 Tcl {} 运算符而不是“”。这个运算符就像 bash 中的单引号,它的意思是“文字字符串,不要以任何方式解释内容”,在这里很合适,因为我想将此字符串逐字传递给生成的 bash 子进程。
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:
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.
send
行末尾缺少一个"
。There is a
"
missing at the end of yoursend
line.