Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to access some server via SSH, run some commands and exit. Do this for lots of servers.

I know I can do this for one machine only, with this script :

ssh **IP** << EOF

chown -R **COMMAND 1**

chown -R **COMMAND 2**

chmod -R 775 **COMMAND 3**


But when I try to put this inside of a FOR in SHELL, keeps saying line 17: syntax error: unexpected end of file.}

Here is my code for SSH multiple servers:


#user already added to group nagios by LDAP

declare -a arr=( **IP1 IP2 IP3** ...)

for i in ${arr[@]}
   echo  "Acessing server $i"
   ssh IP << EOF
   chown -R COMMAND 1
   chown -R COMMAND 2
   chmod -R 775 COMMAND 3

Where is my mistake here ?

share|improve this question
up vote 2 down vote accepted

bash is expecting to see EOF at the beginning of a line in your script. Try removing the indent before EOF.

share|improve this answer
It works, thank you! However it prints Pseudo-terminal will not be allocated because stdin is not a terminal., should I be worry about this ? – Valter Silva Mar 1 '13 at 14:29
Not if it works ;) however, to avoid the message you can run the commands without trying to allocate a pty: ssh hostname 'command1; command2; command3'. – Flup Mar 1 '13 at 14:31
great! works perfectly! – Valter Silva Mar 1 '13 at 14:47

Try with newline character after the first EOF and before the last EOF.

Another thing that comes to my mind is that you can also use pssh (paralell SSH) to do the job, I just don#t know if it fits your project.

Hope that helps! :)

share|improve this answer
I didn't know about pssh, I will look into it. Thank you! – Valter Silva Mar 1 '13 at 14:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .