Question

I want to grep ipaddress from file and set it to variable in expect scritp

  send -- "cat $filename |grep ([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\})\r"
  expect -re "([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}) *$prompt$"
  set IP $expect_out(1,string)

but I'm not suceeding. Any idea? I'm using /usr/local/bin/expect. Thanks

Was it helpful?

Solution

From a quick scan, it seems to me you're trying to match a double prompt in your statement. You seem to have a variable followed by a literal prompt at the end of your expect regexp. Are you sure that is what you want?

Aside from that, I strongly recommend that you put expect_internal 1 somewhere at the top of your script, and that way expect will log output showing you what it is (and is not) matching. You really shouldn't be trying to debug regexp matching without it, it's like searching in the dark...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top