[英]Awk inside expect
I'm having errors when sending this to expect 发送期望值时出现错误
send "someagent_id=`ps aux | grep someagent| grep -v grep | awk '{print $2}'`\r"
Error: 错误:
can't read "2": no such variable
while executing
"send "someagent_id=`ps aux | grep someagent| grep -v grep | awk '{print $2}'`\r""
If all you want is the PID for some process, you don't need all this messy thing:
如果您想要的只是某个过程的PID,则不需要所有这些麻烦的事情:
ps aux | grep someagent| grep -v grep | awk '{print $2}'
ps aux | grep someagent| grep -v grep | awk '{print $2}'
ps aux | grep someagent| grep -v grep | awk '{print $2}'
.
ps aux | grep someagent| grep -v grep | awk '{print $2}'
。 ps aux | grep someagent| grep -v grep | awk '{print $2}'
You can get a process PID just with pgrep
: 您可以使用pgrep
来获取进程PID:
In your case it would be: 您的情况是:
send "someagent_id=$(pgrep SOMEAGENT)\r"
try this : 尝试这个 :
someagent_id=$(ps aux | grep someagent| grep -v grep | awk '{print $2}'\r)
send $someagent_id
`` --> previous version $ --> new version. ``->先前版本$->新版本。 Both do the same thing 两者都做同一件事
try this 尝试这个
send "someagent_id=`ps aux | grep someagent| grep -v grep | awk '{print \$2}'`\r"
and maybe better with this 1 pipe only version 也许这个1管道版本更好
send "someagent_id=`ps aux | awk '/someagent/ && ! /awk/ {print \$2}'`\r"
With ps options 使用ps选项
ps -C someagent -o pid=
send "someagent_id=$(ps -C someagent -o pid=)"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.