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
  1. Read a file of server names (.txt) line by line
  2. loop through each server name and connect by ssh

Any suggestions, comments, and ideas?

share|improve this question

closed as too broad by terdon, Mokubai, Tog, Breakthrough, Excellll Jun 29 '13 at 22:23

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

What is your question? – gronostaj Jun 28 '13 at 20:21
Suggestions: search this site and google before posting; don't expect us to do your homework for you, we'll help if you have specific problems but we won't do all of the work; . Comments: explain what you are trying to do, what operating system you are using, whether you connect to the servers with the same username and password, whether you have passwordless access etc etc. Ideas: Use a for loop. – terdon Jun 28 '13 at 20:37
What have you tried? As mentioned before we are not going to simply do this for you. If you have a solution that is not working then we can often help with that but we will not do your work for you. – Mokubai Jun 29 '13 at 10:03
up vote 1 down vote accepted

Try something like this,

while read p; do
    ssh root@$p ...
done < server_names.txt

I have not tested it, but in principle it should loop over servers in server_names.txt and connect to them.

share|improve this answer
in principle it shouldn't work, unless you use the -n ssh option. And i'm even not talking about allowing root connections. – BatchyX Jun 29 '13 at 10:26
@BatchyX why would you need the -n option? You can connect without it and run commands perfectly well. -n is needed if you want to run in the background. Also this kind of root access is often standard, when connecting to different nodes of a cluster for example. – terdon Jul 1 '13 at 14:55
@terdon: you need the -n option because otherwise, ssh will read and eat up stdin and transmit it to the remote host, just in case. also, allowing root access is a generally bad idea. You shouldn't encourage people to do that if it's not genuinely needed. – BatchyX Jul 1 '13 at 18:00
@BatchyX every lab I've worked in allowed root access between machines on the same network. You could not connect as root from outside the network but it was enabled internally. You may well be right and that is not a good idea but it is quite common. As for -n OK, sure it will protect from unwanted stdin reading but your comment said that this solution "shouldn't work" without -n which is most certainly not true. – terdon Jul 1 '13 at 18:07
@terdon: That's scary, to say the least. As for -n, i will not repeat myself. Please try before arguing. This is a known problem which has spawned plenty of questions already. Without -n, ssh WILL read stdin. Whether you like it or not. (and whether the remote command actually need input from stdin or not). – BatchyX Jul 1 '13 at 18:54

Use GNU Parallel and get it done in parallel:

parallel --slf servers.txt --nonall 'echo Hi from; hostname'

10 seconds installation:

 wget -O - | sh

Watch the intro video for a quick introduction:

share|improve this answer

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