input from a file into an expect script ?

Hi,

I have an expect script that logs into a host (via ssh) requests the hostid then exits... I am happy with that.

However how can I run the same script in a kind of 'while read line' and enter lots of hosts? My knowledge is still very limited (as you will soon see) so any other ideas would be appreciated.

I am trying to update a server list with hostids for each host. I have never logged onto each host before and thus have not set up ssh_keygens.

I have attempted to run the following, but it does not like the host input...

> cat ./hostid_gathering

#!/bin/bash

cat ./host_list | while read LINE; do

./expect_script
done

----------------------------------------------------------------------

> cat expect_script

#!/opt/sfw/bin/expect -f

set timeout -1

set USER "me"
set PASSWORD "my_password"
set HOST "$LINE" <------ Input from the while script does not work

spawn ssh -l $USER $HOST
expect "assword:"
send "$PASSWORD\r"

expect "*%"

send "hostid; exit\r"

expect; # waits for eof, so output is flushed?

puts "\n\nexpect script exiting normally\n";

----------------------------------------------------------------------

> ./hostid_gathering

can't read "LINE": no such variable
while executing
"set HOST "$LINE" "
(file "/expect_script" line 7)
can't read "LINE": no such variable
while executing
"set HOST "$LINE" "
(file "/expect_script" line 7)

----------------------------------------------------------------------

Any help would be greatly appreciated...

My next worry will be when the ssh asks for a yes or no answer first, before requesting a Password response.

When you do "./expect_script" you can "./expect_script $LINE" and inside the expect script you can do :
set HOST [lindex $argv 0]

Thanks sysgate - that worked perfectly. :slight_smile: