Re: Expect + telnet problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





2009/9/10 Matthew Hall <lists@xxxxxxxxxx>
On 09/09/09 17:09, Arthur Meeks Meeks wrote:
> Hello,
>
> I'm creating an expect script to:
>
> telnet router
> execute command
> exit
>
> This seems to be quite easy when you have 1 router, the problem is I
> have a list of 40 routers, so I thought about creating a expect script
> but I have gotten some problems.
> The first one is...how to include all the machines?
> I thought about something like: for d in $(cat router_list); do
> expect_script $d;done
>
> And if that worked, the script would take $d and do:
>
> telnet $d
> execute my command
> exit
>
> But I don't know how to accomplish that as the script and the "expect
> --exact" output are different, one per router, basically because:
> expect -exact "telnet router23\r
> Trying 192.168.33.12...\r
> Connected to router23.test.\r
>
> Changes in all the routers, I have tried to delete that whole paragraph
> so it only expects "Login", but it doesn't work.
>
> And also...how to include the script in the "for" loop?.
>
> Any idea will be appreciated.


Try something like this:

cat <<EOF >> telnet.exp
#!/usr/bin/expectk -f

spawn telnet $argv
expect "Username:"
exp_send "myusername\r"
expect "Password:"
exp_send "mypassword\r"
expect -re "(.*)#"
exp_send "sh run\r"
sleep 0.1
exp_send " "
sleep 0.1
exp_send " "
expect -re "(.*)#"
exp_send "exit\r"
exit
EOF

for hostname in `cat list-of-routers`;do expect telnet.exp $hostname|tee
$hostname.log;done

Matt, thanks a lot, this did the trick.

Thank you all guys for all your ideas, you all rock.

A

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux