Currently I'm having an issue to pass a script with arguments to the bash. The limitation is that I can pass them as a string (see $COMMAND)
ssh user@server 'bash -s' < "$COMMAND"
if my $COMMAND contains "foo.sh bar baz", I would get error no such file or directory: foo.sh bar baz
Additionally, I'm be able to set additional options to bash.
Thank you in advance!!!
The root problem is that <
takes a filename to redirect from, not a filename and some arguments. Mixing the two together this way just won't work.
If I'm understanding right, you want to run a script that exists on the local computer, but have it execute (with the supplied arguments) on the remote computer. In that case, what you want to run is something like this:
ssh user@server 'bash -s bar baz' <"foo.sh"
Note that the arguments are passed in a completely different place than the script filename. If possible, I'd recommend never mixing the two; keep them in separate variables, and then use something like this:
ssh user@server "bash -s $scriptargs" <"$scriptfile"