views:

66

answers:

1

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 "pattern"]

Please advise the reason.

A: 

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)
}
glenn jackman
I offer two implementation details that Glenn fully understands, but that might be of value to user451404 or other readers: 1. "... while 1 ..." in Expect source is often more idiomatically expressed with exp_continue; and, depending on the nature of "whatever" at the top, it might be preferable to write this script in terms of Expect-free standard line-oriented Tcl.
Cameron Laird
Thanks Gleen, it works for me :-) @Cameron, thanks for your input :-)
Ashish
ah, sorry, thanks Glenn :-)
Ashish