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)
}
精彩评论