Reputation: 1755
I run a script which calls another script through a ssh connection.
My script executes the following command:
ssh $cluster "bash $create 2 2 $parts"
where $cluster
is the ssh string and $create
is the absolute path of the bash script on the target machine. I run ssh $cluster "mkdir $serialized/$number"
a few lines earlier, which works just fine.
However this command returns me:
bash: /data/.../create.bash 1 2 8: No such file or directory
The file is on the machine and I can execute the command there, but I can't figure out how to do it from within of a script over ssh. I tried different command, always receive this exception.
Thanks for your help!
Upvotes: 3
Views: 6310
Reputation: 359875
Remove the quotes:
ssh $cluster bash $create 2 2 $parts
or put them only around the arguments:
ssh $cluster bash "$create 2 2 $parts"
if your variable values include spaces:
ssh $cluster bash "'$create' 2 2 '$parts'"
Upvotes: 2
Reputation: 22252
Generally you shouldn't need to call bash in the first place. Even if the shell used by the remote machine isn't bash by default, you should set up the create.bash script such that the top of it looks like:
#!/bin/bash
and it'll already invoke bash.
Other things to consider:
put in the full path to bash in case the path is problematic.
make sure bash exists on the remote host, otherwise try 'sh' instead.
Upvotes: 2
Reputation: 61369
Are you sure the quoting in the script is the same you quoted? I would expect that error from:
ssh $cluster "bash '$create 2 2 $parts'"
or similar.
(Note that when you get an error of the form
bash: mumble: No such file or directory
the mumble is taken as an entire string, so in this case it is looking for a file literally called /data/.../create.bash 1 2 8
, with the spaces and digits being taken as part of the script name instead of as parameters.)
Upvotes: 2