Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

4 Answers 4

up vote 2 down vote accepted

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

ssh root@MachineB 'bash -s' < local_script.sh

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

share|improve this answer

Use this command:

ssh user@host <<'my.sh'
#script to run on remote host
my.sh
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 at 5:52

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

i.e:

while read line
do
  echo Trying to configure server [IP]: $line >> error.log
  scp my-script.sh $line:/root/scripts/ &>> error.log
  ssh root@$line 'cd /root/scripts && ./my-script.sh' &> 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 at 5:53

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.