0

I have two scripts. Both scripts are on the same server (serverA)

The first one (serverA) makes an ssh connection to the other server (serverB), and executes the second script,

e.g

*script1*
ssh $ipaddress var="$var1" "bash -s" < $script2

script2 then executes on serverB.

Is there a way to combine these into one script? So it would start by making the ssh connection, then execute the rest of the script, something like:

#!/bin/bash

#Make an SSH Connection to another server
ssh $ipaddress

#Now Execute the rest of the script
do stuff here . . .
and here . . .
1
ssh $ipaddress /bin/bash <<END
do stuff here . . .
and here . . .
END
0

assumming script2 in local dir

#!/bin/bash
if scp script2 $ipaddress:/tmp
then
   ssh $ipaddress /tmp/script2 "arg" >& /my/result.$ipaddress
   ssh $ipaddress rm /tmp/script2 
fi

you'll pay an extra transfert, but if script2 is non trivial (e.g. not just a tail or wc ), it might be worth.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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