Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

silent ssh is setup from server A to server B (and some 500 other servers)
I have written a script on server A (shell and perl) that I want to execute via ssh on server B (and the other 500 servers). Is this possible ? I am able to run commands using silent ssh but not sure how to run entire scripts.

share|improve this question
up vote 6 down vote accepted

If Server A is a Unix/Linux-based system, you can use:

ssh root@MachineB 'bash -s' <

You shouldn't have to copy the script to the remote server to run it.

share|improve this answer
What does the -s stand for in this context? How is this different than Innovator's answer ? – blong Jul 30 '15 at 14:08

Use this command:

ssh user@host <<''
#script to run on remote host
share|improve this answer

Since silent ssh is already setup is already setup as you say, I would scp the file the file and execute it locally


while read line
  echo Trying to configure server [IP]: $line >> error.log
  scp $line:/root/scripts/ &>> error.log
  ssh root@$line 'cd /root/scripts && ./' &> error.log
  echo Finished working with [IP]: $line >> error.log
done <client-ips.txt

Running the script on client site is less error prone than parsing it with < << operators.

Something similar to the script above should do most of the work for you (hopefully all). Also it will keep track of anything ( &> forwards error messages) that went wrong so you know which IP addresses you need to attend manually.

share|improve this answer
As clearly mentioned, I do not want to copy the file over. – user1074593 Aug 5 '14 at 5:53
Sorry, where is that "clearly mentioned"? – MadHatter May 4 '15 at 21:37
# Source :
# usage: localscript interpreter remoteuser remotehost arg1 arg2 ...
# example: bash pi database user

shift 4

declare -a args

for arg in "$@"; do
  args[count]=$(printf '%q' "$arg")

ssh $user@$host "cat | ${interpreter} /dev/stdin" "${args[@]}" < "$realscript"
# Note: you may need to add options or hardcode keys and such into the above command; example of this commented bellow
# ssh -i <path/to/key> -p <port> $user@$host "cat | ${interpreter} /dev/stdin" "${args[@]}" < "$realscript"

Above is a script I found with a little searching about and modified a bit to show an example of usage and example of using keys for connections as the OP stated that it would be run on many other servers. This script also is coded such that you may pass arguments to the local script and specify the program that the server should use to recieve the script's commands; ie you may tell your server to use perl or python or java... and then give it that related script :-D The source I found the above script is hard coded into it's comments such that copy/past will still allow you years latter to find the original authors ;-)

Happy networking to you all.

share|improve this answer

You can execute remote commands over ssh like

ssh user@serverA /path/to/your/script

share|improve this answer
This will execute the script on serverA ! Its not what I want. – user1074593 Aug 5 '14 at 5:52

Your Answer


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.