Issue
How to execute the local bash script file with the references on the remote server using ssh?
a.sh
#!/bin/bash
echo A
source b.sh
b.sh
#!/bin/bash
echo B
Executing on the remote ssh server:
cat a.sh | ssh myserver
A
-bash: line 4: b.sh: No such file or directory
What are the options for solving this issue without copying files to the remote server?
Solution
As long as you only have references with one level of depth, you can use awk to directly insert the contents of the referenced file into the first one.
$ awk '/^source/{while((getline line < $2) > 0){print line}close($2);next}1' a.sh
This outputs:
#!/usr/bin/bash
echo A
#!/usr/bin/bash
echo B
So you could use it like this:
$ awk '/^source/{while((getline line < $2) > 0){print line}close($2);next} +1' a.sh | ssh myserver
If you wanted to use dependencies with more depth, you could apply this same command in a loop until the result file didn't change.
Answered By - Miguel