I have a program on a remote host, whose execution I need to automate. The command execute that program, on the same machine, looks something like this:
/path/to/program -a file1.txt -b file2.txt
In this case, file1.txt
and file2.txt
are used for entirely different things within the program, so I can't just cat
them together. However, in my case, the file1.txt
and file2.txt
that I want to pass into the program exist only on my device, not on the host where I need to execute the program. I know that I can feed at least one file through SSH by passing it through stdin
:
cat file1.txt | ssh host.name /path/to/program -a /dev/stdin -b file2.txt
but, since I'm not allowed to store files on the host, I need a way to get the file2.txt
over there as well. I'm thinking it might be possible through abuse of environment variables and creative use of cat
and sed
together, but I don't know the tools well enough to understand how I would use them to accomplish this. Is it doable, and how?
Best Answer
If the files given as arguments to your program are text files, and you're able to control their content (you know a line which doesn't occur inside them), you can use multiple here-documents:
Here
cat
is a sample command which takes filenames as arguments. It could be instead:Replace each
EOT
with something that doesn't occur in each of the files, respectively.