<br><br><div class="gmail_quote">2009/9/10 Matthew Hall <span dir="ltr"><<a href="mailto:lists@ecsc.co.uk">lists@ecsc.co.uk</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5">On 09/09/09 17:09, Arthur Meeks Meeks wrote:<br>
> Hello,<br>
><br>
> I'm creating an expect script to:<br>
><br>
> telnet router<br>
> execute command<br>
> exit<br>
><br>
> This seems to be quite easy when you have 1 router, the problem is I<br>
> have a list of 40 routers, so I thought about creating a expect script<br>
> but I have gotten some problems.<br>
> The first one is...how to include all the machines?<br>
> I thought about something like: for d in $(cat router_list); do<br>
> expect_script $d;done<br>
><br>
> And if that worked, the script would take $d and do:<br>
><br>
> telnet $d<br>
> execute my command<br>
> exit<br>
><br>
> But I don't know how to accomplish that as the script and the "expect<br>
> --exact" output are different, one per router, basically because:<br>
> expect -exact "telnet router23\r<br>
> Trying 192.168.33.12...\r<br>
> Connected to router23.test.\r<br>
><br>
> Changes in all the routers, I have tried to delete that whole paragraph<br>
> so it only expects "Login", but it doesn't work.<br>
><br>
> And also...how to include the script in the "for" loop?.<br>
><br>
> Any idea will be appreciated.<br>
<br>
<br>
</div></div>Try something like this:<br>
<br>
cat <<EOF >> telnet.exp<br>
#!/usr/bin/expectk -f<br>
<br>
spawn telnet $argv<br>
expect "Username:"<br>
exp_send "myusername\r"<br>
expect "Password:"<br>
exp_send "mypassword\r"<br>
expect -re "(.*)#"<br>
exp_send "sh run\r"<br>
sleep 0.1<br>
exp_send " "<br>
sleep 0.1<br>
exp_send " "<br>
expect -re "(.*)#"<br>
exp_send "exit\r"<br>
exit<br>
EOF<br>
<br>
for hostname in `cat list-of-routers`;do expect telnet.exp $hostname|tee<br>
$hostname.log;done</blockquote><div><br>Matt, thanks a lot, this did the trick.<br><br>Thank you all guys for all your ideas, you all rock.<br><br>A <br></div></div><br>