For loop not working with Expect script
Hi All,
I have written an expect script to login into another server using ssh. But, when I want to do the same for multiple servers using a for loop, it doesnt work.
Below is the script:
#!/usr/bin/expect
match_max 5000
set expect_out(buffer) {}
for i in `cat node_list.txt`
do
node_ip=`echo $i| awk -F"," '{print $1}'`
node_initial_pwd=`echo $i| awk -F"," '{print $2}'`
spawn ssh root@$node_ip
expect {
"*(yes/no)?" {send "yes\r";exp_continue}
"'s password:" {send "$node_initial_pwd\r";exp_continue}
"*current*" {send "$node_initial_pwd\r";exp_continue}
"Enter*" {send "Jan2016!\r";exp_continue}
"Retype*" {send "Jan2016!\r";exp_continue}
"\\\$" { puts "matched prompt"}
}
done
---------
node_list.txt has IP's and passwords separated by a comma(,).
---------
Error I get is this:
mayankp@mayankp:~/scripts/new$ ./connect-to-server.sh
invalid command name "i"
while executing
"i"
("for" initial command)
invoked from within
"for i in `cat node_list.txt`"
(file "./connect-to-server.sh" line 6)
Can you please help me in achieving this?
|