Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have a somewhat lengthy script which sources other scripts to include the functions there. I'd like to execute this script remotely via ssh.

Now I thought to make one script file of it (without sourcing it) and then let it execute remotely via ssh.

For example the idea was something like this, unfortunately it does not work:

$ ssh user@host < $(cat dep1.sh dep2.sh main.sh)

whereas when it is a single file (I merged it before) does work:

$ ssh user@host < complete_main_script.sh

Any ideas how I would overcome the issue, i.e. make one script file of the three above and send it as a whole via ssh?

share|improve this question
2  
Yeah, ok. It's as simple as that cat dep1.sh dep2.sh main.sh | ssh user@host bash -s Ok, well, Mr. Obvious is done here... ;) –  implicit_knowledge Jan 17 '14 at 9:09
1  
to send file with ssh it's a lot eaiser to use scp if enable on your server –  Kiwy Jan 17 '14 at 9:14
1  
@Kiwy OP is not transferring the file as such, rather executing commands therein. –  peterph Jan 17 '14 at 9:16
    
@peterph I missunderstand sorry. –  Kiwy Jan 17 '14 at 9:23
    
if you find the answer please add it and accept it after 24h –  Kiwy Jan 17 '14 at 9:28

1 Answer 1

$(command) is (as the generalized syntax suggests) command substitution - you can think of it as a placeholder for the verbatim output of the command. Hence:

$ ssh user@host < $(cat dep1.sh dep2.sh main.sh)

Stands for something like:

$ ssh user@host < "#!/bin/sh
rest your dep1.sh script goes here
#!/bin/sh
rest of your dep2.sh script goes here
...
"
share|improve this answer

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.