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.
Arthur.
--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
Hi.
I am not sure, but you could do something like this:
rlist.txt:
host1
host2
...
#! /usr/bin/tclsh
package require Expect
set fl [open [pwd]/rlist.txt]
set routers [read $fl]
set login "me"
set password "awsdzxcv"
foreach router $routers {
spawn telnet $router
expect {login:}
send "$login\r"
expect {Password:}
send "$password\r"
expect -re {\$}; # router prompt
send "ls\r"; # your command
expect -re {\$}
send "exit\r"
expect -re {\$}; #your host prompt
}
~B
-- fedora-list mailing list fedora-list@xxxxxxxxxx To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines