2

Why I cannot execute command on remote host. Do I miss something?

Bash file: hello.sh

#!/bin/sh 
host_name="myHost"
ssh $host_name  '
STR="Hello World!"
echo $STR
'

executing above file: the print out:
 > ./print_node_status.sh
Enter Windows password: 
STR=Hello World!: Command not found.
STR: Undefined variable.
1
  • Not sure why that prompt asks for a "Windows password". I will be assuming that it is a linux node anyway. Commented Sep 5, 2017 at 7:56

1 Answer 1

1

It looks like your remote shell is the C shell, not Bash.

You have several options:

  • Adapt your code to conform to that shell's language:

   ssh $host_name  '
   set STR="Hello World\!"
   echo $STR
   '
  • Execute /bin/bash in your remote process, if it is available, e.g.:

   ssh $host_name  '
   exec /bin/bash
   STR="Hello World!"
   echo $STR
   '
  • Change the default shell of your user on that node to /bin/bash, see the chsh(1) manpage.
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.