开发者

No result on standard output when running expect

开发者 https://www.devze.com 2023-01-17 11:30 出处:网络
Whenever I try to run the script it doesn\'t show me any result on standard output. #!/usr/bin/expect --

Whenever I try to run the script it doesn't show me any result on standard output.

#!/usr/bin/expect --
send [exec tail -f /var/opt/jboss/log/jbossall.log | grep -i "开发者_如何学Gopattern"]

Please advise the reason.


The exec command never completes because you're using tail -f. From the info page for tail: "Loop forever trying to read more characters at the end of the file". Since exec does not complete, send is never invoked.

You probably need to do something like this:

spawn whatever
set whatever_id $spawn_id

spawn sh -c {tail -f /var/opt/jboss/log/jbossall.log | grep -i "pattern"}
set tail_id $spawn_id

while {1} {
    expect -i $tail_id "(.*)\n"
    send -i $whatever_id $expect_out(1,string)
}
0

精彩评论

暂无评论...
验证码 换一张
取 消