run a shell script which reference another script on ssh
Clash Royale CLAN TAG#URR8PPP
I have two bash scripts main.sh
and a util.sh
, and I reference utils.sh
in the main.sh
by using . util.sh
. Now I want to run main.sh
via ssh. Obviously, this won't work:
ssh user@host "bash /dev/stdin < main.sh"
Because remote shell cannot find util.sh
. So how should I do this, without copying util.sh
to remote machine ?
bash shell ssh
add a comment |
I have two bash scripts main.sh
and a util.sh
, and I reference utils.sh
in the main.sh
by using . util.sh
. Now I want to run main.sh
via ssh. Obviously, this won't work:
ssh user@host "bash /dev/stdin < main.sh"
Because remote shell cannot find util.sh
. So how should I do this, without copying util.sh
to remote machine ?
bash shell ssh
To run a remote scriptssh user@host main.sh
would be enough actually. Why can't you just copyutil.sh
over as well?
– nohillside
Dec 24 '18 at 9:15
Maybeutils.sh
is a common module and reused by many scripts
– Lewis Chan
Dec 24 '18 at 9:31
1
You still can deploy it tohost
together withmain.sh
. Or put it onto a shared/network drive somewhere. Or havemain.sh
check whether it is available locally and download it from somewhere if not.
– nohillside
Dec 24 '18 at 9:49
add a comment |
I have two bash scripts main.sh
and a util.sh
, and I reference utils.sh
in the main.sh
by using . util.sh
. Now I want to run main.sh
via ssh. Obviously, this won't work:
ssh user@host "bash /dev/stdin < main.sh"
Because remote shell cannot find util.sh
. So how should I do this, without copying util.sh
to remote machine ?
bash shell ssh
I have two bash scripts main.sh
and a util.sh
, and I reference utils.sh
in the main.sh
by using . util.sh
. Now I want to run main.sh
via ssh. Obviously, this won't work:
ssh user@host "bash /dev/stdin < main.sh"
Because remote shell cannot find util.sh
. So how should I do this, without copying util.sh
to remote machine ?
bash shell ssh
bash shell ssh
asked Dec 24 '18 at 9:13
Lewis Chan
61
61
To run a remote scriptssh user@host main.sh
would be enough actually. Why can't you just copyutil.sh
over as well?
– nohillside
Dec 24 '18 at 9:15
Maybeutils.sh
is a common module and reused by many scripts
– Lewis Chan
Dec 24 '18 at 9:31
1
You still can deploy it tohost
together withmain.sh
. Or put it onto a shared/network drive somewhere. Or havemain.sh
check whether it is available locally and download it from somewhere if not.
– nohillside
Dec 24 '18 at 9:49
add a comment |
To run a remote scriptssh user@host main.sh
would be enough actually. Why can't you just copyutil.sh
over as well?
– nohillside
Dec 24 '18 at 9:15
Maybeutils.sh
is a common module and reused by many scripts
– Lewis Chan
Dec 24 '18 at 9:31
1
You still can deploy it tohost
together withmain.sh
. Or put it onto a shared/network drive somewhere. Or havemain.sh
check whether it is available locally and download it from somewhere if not.
– nohillside
Dec 24 '18 at 9:49
To run a remote script
ssh user@host main.sh
would be enough actually. Why can't you just copy util.sh
over as well?– nohillside
Dec 24 '18 at 9:15
To run a remote script
ssh user@host main.sh
would be enough actually. Why can't you just copy util.sh
over as well?– nohillside
Dec 24 '18 at 9:15
Maybe
utils.sh
is a common module and reused by many scripts– Lewis Chan
Dec 24 '18 at 9:31
Maybe
utils.sh
is a common module and reused by many scripts– Lewis Chan
Dec 24 '18 at 9:31
1
1
You still can deploy it to
host
together with main.sh
. Or put it onto a shared/network drive somewhere. Or have main.sh
check whether it is available locally and download it from somewhere if not.– nohillside
Dec 24 '18 at 9:49
You still can deploy it to
host
together with main.sh
. Or put it onto a shared/network drive somewhere. Or have main.sh
check whether it is available locally and download it from somewhere if not.– nohillside
Dec 24 '18 at 9:49
add a comment |
2 Answers
2
active
oldest
votes
Even though I think deploying util.sh
to host
would be the better/more stable solution, you could do something like putting this on top of main.sh
#!/bin/bash
U=$(mktemp)
cat > "$U"
. "$U"
rm -f "$U"
# rest of script
and then run
ssh user@host main.sh < util.sh
To be more fail-safe you may require some extra coding in main.sh
to handle issues with the temp file being unwritable/undeletable, no input passed on stdin
etc.
add a comment |
This is ugly, but should work:
ssh user@host bash < <(sed 's/. util.sh/ r util.sh; d' main.sh)
That will embed the contents of the util script into the main script, and then pipe the script to the bash process running on the remote host.
Note that I've removed the double quotes: the process substitution needs to run on your local machine where both files reside.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f490735%2frun-a-shell-script-which-reference-another-script-on-ssh%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Even though I think deploying util.sh
to host
would be the better/more stable solution, you could do something like putting this on top of main.sh
#!/bin/bash
U=$(mktemp)
cat > "$U"
. "$U"
rm -f "$U"
# rest of script
and then run
ssh user@host main.sh < util.sh
To be more fail-safe you may require some extra coding in main.sh
to handle issues with the temp file being unwritable/undeletable, no input passed on stdin
etc.
add a comment |
Even though I think deploying util.sh
to host
would be the better/more stable solution, you could do something like putting this on top of main.sh
#!/bin/bash
U=$(mktemp)
cat > "$U"
. "$U"
rm -f "$U"
# rest of script
and then run
ssh user@host main.sh < util.sh
To be more fail-safe you may require some extra coding in main.sh
to handle issues with the temp file being unwritable/undeletable, no input passed on stdin
etc.
add a comment |
Even though I think deploying util.sh
to host
would be the better/more stable solution, you could do something like putting this on top of main.sh
#!/bin/bash
U=$(mktemp)
cat > "$U"
. "$U"
rm -f "$U"
# rest of script
and then run
ssh user@host main.sh < util.sh
To be more fail-safe you may require some extra coding in main.sh
to handle issues with the temp file being unwritable/undeletable, no input passed on stdin
etc.
Even though I think deploying util.sh
to host
would be the better/more stable solution, you could do something like putting this on top of main.sh
#!/bin/bash
U=$(mktemp)
cat > "$U"
. "$U"
rm -f "$U"
# rest of script
and then run
ssh user@host main.sh < util.sh
To be more fail-safe you may require some extra coding in main.sh
to handle issues with the temp file being unwritable/undeletable, no input passed on stdin
etc.
answered Dec 24 '18 at 10:05
nohillside
2,382919
2,382919
add a comment |
add a comment |
This is ugly, but should work:
ssh user@host bash < <(sed 's/. util.sh/ r util.sh; d' main.sh)
That will embed the contents of the util script into the main script, and then pipe the script to the bash process running on the remote host.
Note that I've removed the double quotes: the process substitution needs to run on your local machine where both files reside.
add a comment |
This is ugly, but should work:
ssh user@host bash < <(sed 's/. util.sh/ r util.sh; d' main.sh)
That will embed the contents of the util script into the main script, and then pipe the script to the bash process running on the remote host.
Note that I've removed the double quotes: the process substitution needs to run on your local machine where both files reside.
add a comment |
This is ugly, but should work:
ssh user@host bash < <(sed 's/. util.sh/ r util.sh; d' main.sh)
That will embed the contents of the util script into the main script, and then pipe the script to the bash process running on the remote host.
Note that I've removed the double quotes: the process substitution needs to run on your local machine where both files reside.
This is ugly, but should work:
ssh user@host bash < <(sed 's/. util.sh/ r util.sh; d' main.sh)
That will embed the contents of the util script into the main script, and then pipe the script to the bash process running on the remote host.
Note that I've removed the double quotes: the process substitution needs to run on your local machine where both files reside.
answered Dec 24 '18 at 13:20
glenn jackman
50.4k570107
50.4k570107
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f490735%2frun-a-shell-script-which-reference-another-script-on-ssh%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
To run a remote script
ssh user@host main.sh
would be enough actually. Why can't you just copyutil.sh
over as well?– nohillside
Dec 24 '18 at 9:15
Maybe
utils.sh
is a common module and reused by many scripts– Lewis Chan
Dec 24 '18 at 9:31
1
You still can deploy it to
host
together withmain.sh
. Or put it onto a shared/network drive somewhere. Or havemain.sh
check whether it is available locally and download it from somewhere if not.– nohillside
Dec 24 '18 at 9:49