I'm pretty new to shell/bash scripting and I'm writing a script on OSX to automate some rather tedious efforts. I'm trying to run a portion of my script on a remote host using
ssh. There's a common script on both machines, which I'll call
ascript. On both machines, this script is in /usr/local/bin.
I know that I need the full path to
ascript on my remote host to run it like so:
ssh user@otherHost bash -c "/usr/local/bin/ascript --FlagToDoSomething"
However, I've found that
--FlagToDoSomething only runs correctly if I write it the following way in my script:
ssh user@otherHost bash -c "
(ie it needs a new line after the open quotes) I get a message in the Terminal window saying
bash: -c: option requires an argument, but the rest of it continues to run and I get the output that I'm expecting. If I don't do that, I just get the output as though I just typed in
ascript and hit enter (so the usage info).
If I remove
bash -c it works correctly, but I'm only doing it this way because, for whatever reason:
ssh user@otherHost "output=$(/usr/local/bin/ascript --FlagToDoSomething; echo \$output)"
attempts to run this function on the local host, which causes some funky output. And I need to run multiple commands on the remote host before terminating my ssh connection.