0

I'm trying to execute a local script remotely using SSH for now here is how I'm doing it:

function remoteRun{

if [ $# -ls 2 ]; then
    usage()
    exit 1
fi
    ssh $1@$2 'bash -s' < $3
}
remoteRun user host script.sh

Now I'm trying to do the same thing but passing some arguments to the script.sh script.

Do you think that something like will work as expected?

remoteRun user host script.sh all step

If not, what is your best practice when you need to generate a script on Box A but execute them in Box B ?

  • mount box A via nfs on box B. – Ipor Sircer Oct 27 '16 at 11:51
  • I can't use a mount or git as the runner is Jenkins which provide some parameters variables. – Dr I Oct 27 '16 at 12:13
  • Why not send the script over(SCP/rsync) to that server and then execute the script? – Orphans Oct 27 '16 at 13:02
  • As I said, my script use some jenkins variables, that's why I ask if args can be added on the 'classic' way to do that. – Dr I Oct 27 '16 at 13:04
1
function remoteRun()
{

   if [ $# -ls 2 ]; then
      usage()
      exit 1
   fi

cat << FOOF > /tmp/script
ls -l /var/log/
FOOF

   scp /tmp/script user@host:/tmp/
   ssh user@host "bash /tmp/script"
}

remoteRun user host script.sh

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.