<br><br><div class="gmail_quote">2009/9/10 Matthew Hall <span dir="ltr">&lt;<a href="mailto:lists@ecsc.co.uk">lists@ecsc.co.uk</a>&gt;</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>
&gt; Hello,<br>
&gt;<br>
&gt; I&#39;m creating an expect script to:<br>
&gt;<br>
&gt; telnet router<br>
&gt; execute command<br>
&gt; exit<br>
&gt;<br>
&gt; This seems to be quite easy when you have 1 router, the problem is I<br>
&gt; have a list of 40 routers, so I thought about creating a expect script<br>
&gt; but I have gotten some problems.<br>
&gt; The first one is...how to include all the machines?<br>
&gt; I thought about something like: for d in $(cat router_list); do<br>
&gt; expect_script $d;done<br>
&gt;<br>
&gt; And if that worked, the script would take $d and do:<br>
&gt;<br>
&gt; telnet $d<br>
&gt; execute my command<br>
&gt; exit<br>
&gt;<br>
&gt; But I don&#39;t know how to accomplish that as the script and the &quot;expect<br>
&gt; --exact&quot; output are different, one per router, basically because:<br>
&gt; expect -exact &quot;telnet router23\r<br>
&gt; Trying 192.168.33.12...\r<br>
&gt; Connected to router23.test.\r<br>
&gt;<br>
&gt; Changes in all the routers, I have tried to delete that whole paragraph<br>
&gt; so it only expects &quot;Login&quot;, but it doesn&#39;t work.<br>
&gt;<br>
&gt; And also...how to include the script in the &quot;for&quot; loop?.<br>
&gt;<br>
&gt; Any idea will be appreciated.<br>
<br>
<br>
</div></div>Try something like this:<br>
<br>
cat &lt;&lt;EOF &gt;&gt; telnet.exp<br>
#!/usr/bin/expectk -f<br>
<br>
spawn telnet $argv<br>
expect &quot;Username:&quot;<br>
exp_send &quot;myusername\r&quot;<br>
expect &quot;Password:&quot;<br>
exp_send &quot;mypassword\r&quot;<br>
expect -re &quot;(.*)#&quot;<br>
exp_send &quot;sh run\r&quot;<br>
sleep 0.1<br>
exp_send &quot; &quot;<br>
sleep 0.1<br>
exp_send &quot; &quot;<br>
expect -re &quot;(.*)#&quot;<br>
exp_send &quot;exit\r&quot;<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>