Score:0

How to pass multiple arguments through ssh and use those arguments in the ssh script?

jp flag

I have written one script on lets say server1 and from that script I want to execute script Start_UI_AdminApp.sh on server2 through ssh. I also need to pass the arguments while executing this ssh command. So that i have to use those arguments in sc.sh. This is my script which I am trying to execute

I am calling my server1 script as below

./server1.sh 3005 BuildNO_7

Below is my script from server1 (server1.sh)

#!/bin/bash
port=$1
directory=$2
ssh user@server2 "bash -s" < /home/server/scripts/Start_UI_AdminApp.sh "$port $directory"
echo "Script executed"

This is the error which I am getting when executing the command ./server1.sh 3005 BuildNO_7

./server1.sh: line 4: /home/server/scripts/Start_UI_AdminApp.sh: No such file or directory
Script executed
Archemar avatar
mx flag
is `/home/server/scripts/Start_UI_AdminApp.sh` on server1 or server2 ? what you want is rather like `bash /home/server/scripts/Start_UI_AdminApp.sh $port $directory` (or without bash if you set execution bit.
Satish Lamak avatar
jp flag
/home/server/scripts/Start_UI_AdminApp.sh is on server 2.
Archemar avatar
mx flag
then what you want is `ssh user@server2 bash /home/server/scripts/Start_UI_AdminApp.sh $port $directory`
Satish Lamak avatar
jp flag
Thank Archemar it worked.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.