unix - For loop not working in expect sript -
i have written expect script login server using ssh. but, when want same multiple servers using loop, doesnt work. below script:
#!/usr/bin/expect match_max 5000 set expect_out(buffer) {} in `cat node_list.txt` 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 , passwords separated comma(,). error this:
mayankp@mayankp:~/scripts/new$ ./connect-to-server.sh invalid command name "i" while executing "i" ("for" initial command) invoked within "for in `cat node_list.txt`" (file "./connect-to-server.sh" line 6)
can please me in achieving this? know mixing bash , expect here, have no clue how run loop in expect.
as say, mixing shell , expect syntax here. expect based on tcl, documentation of generic language commands can found @ http://www.tcl.tk/man/tcl/tclcmd/contents.htm .
a rough untested translation of loop trying write is
set inputchannel [open node_list.txt] while {[gets $inputchannel line] != -1} { set fields [split $line ,] set node_ip [lindex $fields 0] set node_initial_pwd [lindex $fields 1] spawn ssh root@$node_ip ...etc... }
Comments
Post a Comment