[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]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux