1

I'm trying to run a local script remotely that I'm calling with some other code. The basic formate is

ssh -i ${PemKey} ${User}@${URL} 'bash -s' -- < ${Command}

I get the error line 24: ${Command}: ambiguous redirect Command is a string with the name of the script I want to run and its arguments. If I change the script to just print the command as

echo "ssh -i ${PemKey} ${User}@${URL} 'bash -s' -- < ${Command}"

and then run the command myself it works just fine. I've tried putting the command in a temp variable and then call it that way, like:

TEMP="ssh -i ${PemKey} ${User}@${URL} 'bash -s' -- < ${Command}"
$TEMP
echo $TEMP

This results in No such file or directory. Again the echoed version of the command runs just fine at the command line.

Anyone know what I'm doing wrong here?

5
  • Well, this works for me: echo pwd | ssh localhost bash -s Commented Sep 15, 2014 at 23:03
  • 1
    This also works: ssh localhost bash -s <<< pwd. But this doesn't: ssh localhost bash -s < pwd. Commented Sep 15, 2014 at 23:14
  • 1
    Use double quotes around "${Command}" (and all your other variables). Also, don't copy-paste parts of error messages: e.g. bash: : No such file or directory tells you way more than just the human readable text. Commented Sep 15, 2014 at 23:33
  • Gaah, I had quotes around the string in my Command variable so hadn't put them around it the way you have it. Moving them fixes everything, thanks. If you want to post that as an answer I'll happily accept it. Commented Sep 16, 2014 at 0:36
  • Actually no... that gets ride of the ambiguous redirect error but again triggers the file not found dir because it looks for the script on the remote machine. Commented Sep 16, 2014 at 2:06

1 Answer 1

1

It seems that executing $TEMP doesn't work correctly, as the whole string 'bash -s' -- < ${Command} is given in argument to ssh. And in fact if you create a file called ${Command} on you remote host you will get an error bash: bash -s: command not found.

A solution is to uses eval like this :

eval $TEMP

This really does what it should.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.