| |||||||||||
expect reading in a list???? Posted by Dr._Byte (Dr._Byte), 18 November 2004 Help, I know that I cant do this, I have in the past but I cant for the life of me remember how and I know this should be trivial..... But I have a script that I need to take input from a file... i.e. I want to have a file with a list of ip's and have the expect script run against each of the ip's in the list. Can I do this in expect or am I going to have to write aperl wrapper for it? Thanks William Posted by admin (Graham Ellis), 18 November 2004 Here's some expect code to open a file, read line by line, extract information ....Code:
all you need to do is alter the switch to something more appropriate drop your expect code in the loop. No need to use any Perl, great language though it is Posted by Dr._Byte (Dr._Byte), 18 November 2004 Thanks for the information... I will give that a try... in the mean time I wrote a ksh script to call the expect script. If you are interested in the code for that I can post it here... Thanks again William Posted by admin (Graham Ellis), 18 November 2004 Yep, do post (the ksh script) .. thanks!Posted by Dr._Byte (Dr._Byte), 18 November 2004 No problem at all.... here you go... very simple script I will comment it as well... #!/bin/ksh #useage testscript hostfile cat $1 | while read host do ./test.exp $host done useage is testscript.sh filecontainingIPaddresses the script reads in the file that was put on the command line cats it and increments by 1 at each pass and the do then executes the expect script test.exp $host where $host is the IP address it read on each line of the hostfile. the expect script in this case just is a typical login shell script... this is the test.exp file #!/usr/local/bin/expect -f # Useage login site if { $argc < 1 } { send_user "Usage: fdl site \n" exit } set site [lindex $argv 0] set pass "testpass" spawn telnet $site expect { {*Name :*} {send "name\r"; expect {*assword:*}; send {pass}\r; expect {*>*} } } exit expect { {*Name :*} {send_user "ACCESS DENIED Invalid password"; exit} } exit Very simple this will walk through the ip addresses you have set in the host file and attempt to telnet in to them... Using the username and password you assigned. What I was goign to use this for was to verify if I have changed my passwords to the systems I have access to. This can easily be adapted to log the results to a file or using expect go in and change the ones that still have the "old" password. Thanks William This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |