Results 1 to 7 of 7
hello!
I'm using expect to log in to cisco routers and get their show run/vers. I've hit a snag expecting the prompts, so what I now plan to do is ...
- 03-19-2008 #1Just Joined!
- Join Date
- Mar 2008
- Posts
- 26
Expect: Creating variables on the fly
hello!
I'm using expect to log in to cisco routers and get their show run/vers. I've hit a snag expecting the prompts, so what I now plan to do is use "show run | i hostname" (which will return any line with "hostname" on it) and then grab the hostname (the next string) and use it as a variable. Is this even possible?
How can this be done?
- 03-19-2008 #2
- 03-19-2008 #3Just Joined!
- Join Date
- Mar 2008
- Posts
- 26
Expect.
That's based on TCL by the way.
*edit* Wait, did you mean the "sh run |i hostname"? That's just a cisco IOS command, and it's not relevant - it's a remote comand I'm using to get the output - it's how to process the output I'm interested in.
- 03-19-2008 #4
I'm not an expect expert. But my O'Reilly book on expect says:
Since I don't know how to use variables in expect, you get to figure that out. :) Go here.expect stores the matched characters [from the input] in a variable called expect_out(0,string).
Hope this gets you started.--
Bill
Old age and treachery will overcome youth and skill.
- 03-19-2008 #5Just Joined!
- Join Date
- Mar 2008
- Posts
- 26
I wish I had that book. I've been getting extracts from it all day from O'reilly's site. However, I've tried using $expect_out(0,string) verbose, and it doesn't ever work for me.
You see $expect_out is an array, and the only thing that seems to be in the array for me is the variable (buffer), which is basically the last command/response up to the last expect. I can get that to output 4 lines of code:
Prompt
good info
useless info
prompt
and I just need the "info" I've bolded in green as my variable. I've created a workaround, so it's not as important now, but I had this idea as a flash of inspiration last night, and if it's workable, it would be helluva useful for getting specific prompts on cisco equipment.
Thanks again for replying Bill - I think I might need to get me that book!
>_> Maybe I can get work to buy it...
- 03-19-2008 #6
What happened when you went to the linky?
--
Bill
Old age and treachery will overcome youth and skill.
- 03-19-2008 #7Just Joined!
- Join Date
- Mar 2008
- Posts
- 26
Oh, I've been there before tbh, and I found it very unhelpful. the o'reilly site is much better, chapter 3 is online, and each section has exerpts you can read. I've learned more from that in one day (today) than I have in the 2 previous days I spent sat here figuring it out.
O'reilly rules man.
I sound like I work for o'reilly now


Reply With Quote