[OT] ssh login script - Please Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@server1:/tmp/
spawn ssh root@server1 /etc/init.d/ntpd restart
arg 1: server2
spawn scp /etc/ntp.conf root@server2:/tmp/
spawn ssh root@server2 /etc/init.d/ntpd restart
root@server2's password:
Shutting down ntpd: [  OK  ]
Starting ntpd: [  OK  ]

Any ideas?

Thanks for any help.
Dan

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux