Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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**

EOF

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:

#!/bin/bash

#user already added to group nagios by LDAP

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

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

Where is my mistake here ?

share|improve this question
add comment

2 Answers 2

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
1  
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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.