I've recently learned how great
expect is, now that I'm suddenly responsible for managing 150 VMs. I've been using it to distribute config files to remote servers, but there's got to be a better way than what I'm doing.
Mainly what I do is things like this:
set server [lindex $argv 0] set timeout -1 spawn scp -i $::env(HOME)/.ssh/key.pem file $server:/tmp/ expect ">>" spawn ssh -i $::env(HOME)/.ssh/key.pem $server expect ">>" send "sudo mv /tmp/file /etc/file && sudo service foo restart\r" expect ">>" puts "\r\r"
So basically, the script scp's the file over to the remote server, and then ssh's into the server and moves the file (using sudo, because it's a file owned by root in /etc, e.g.
nscd.conf) to its destination. It seems like there must be a better way than this to manage distributing a new root-owned config file to a bunch of machines.