[OT] ssh login script - Please Help
Dan Track
dan.track at gmail.com
Thu May 7 14:22:03 UTC 2009
Hi
I appreciate this is OT but could someone just give me a little
advice, I've written this script to logon on each server then restart
the ntpd daemon. The problem I have is it only restarts the daemon for
the last server provided in the list, any ideas as to why and how to
fix it?
#!/usr/bin/expect -f
set argc [llength $argv]
for {set i 0} {$i<$argc} {incr i} {
puts "arg $i: [lindex $argv $i]"
set var1 [lindex $argv $i]
spawn scp /etc/ntp.conf "root@$var1:/etc/"
spawn ssh root@$var1 "/etc/init.d/ntpd restart"
}
#######################
expect {
-re ".*es.*o.*" {
exp_send "yes\r"
exp_continue
}
-re ".*sword.*" {
exp_send "<password>\r"
}
}
interact
When run I get the following:
./test.expect server1 server2
arg 0: server1
spawn scp /etc/ntp.conf root at server1:/tmp/
spawn ssh root at server1 /etc/init.d/ntpd restart
arg 1: server2
spawn scp /etc/ntp.conf root at server2:/tmp/
spawn ssh root at server2 /etc/init.d/ntpd restart
root at server2's password:
Shutting down ntpd: [ OK ]
Starting ntpd: [ OK ]
Any ideas?
Thanks for any help.
Dan
More information about the fedora-list
mailing list