Install Script

Say I want to install x on 10 different machines.

Is there a script that will do it for me install of going to each machines and doing it manually ?

if you have a ssh root access to each machine
then yes
else no
fi

:wink:

I do have root access.

Any ideas how to write something like this ?

for Debian something like

#!/bin/bash
for SERVER in ip1 ip2 ip3 .... # list of ip of servers (can be hostames if recognized)
do
    ssh root@$SERVER apt-get install program1 program2 ...
done

for other distros, use the appropriate syntax in state of "apt-get install".

Hello ,
that would again require to manually enter the password at the prompt for all the hosts. So I would recommend using an expect script like this

# Assume $remote_server, $my_user_id, $my_password, and $my_command were read in earlier 
  # in the script.
  # Open a ssh session to a remote server, and wait for a username prompt.
  spawn ssh $remote_server
  expect "password:"
  # Send the password, and then wait for a shell prompt.
  send "$my_password\r"
  expect "%"
  # Send the prebuilt command, and then wait for another shell prompt.
  send "$my_command\r" #apt-get install xorg 
  expect "%"
  # Capture the results of the command into a variable. This can be displayed, or written to disk.
  set results $expect_out(buffer)
  # Exit the ssh session, and wait for a special end-of-file character.
  send "exit\r"
  expect eof

you can enclose the expect statement into a foreach and get to read a text file containing each host's password from some text file.
Hope this helps.
Regards.

Good, i'll have to learn more about expect.
But the passwords can be seen in the script and therefore it's not very secure.
I prefer (it has to be done once for each server but can then be used later) the public key authentication.
But take care: It's secure only if nobody else uses your account on your own computer.

Hi All

If the list of servers is small, i would suggest that you set up passwordless ssh between the servers.
and then use your script without passwords in it.

Cheers