0

The local and remote machine both are Centos 7 machines, and when I run a remote script from the local machine, where the script is in the /home/user_name/scripts directory

I got the following:

$ ssh user_name@192.168.1.xx "bash -s" -- < scripts/machine-info.sh
-bash: scripts/machine-info.sh: No such file or directory

running this returns what is expected:

$ ssh user_name@192.168.1.xx 'scripts/machine-info.sh'
date is:  Thu Jul 25 01:43:35 CEST 2019
Hostname is:  linuxtb3
IP address is: 192.168.1.xx

as well as

$ ssh user_name@192.168.1.xx 'bash -s -- < scripts/machine-info.sh'
date is:  Thu Jul 25 01:45:13 CEST 2019
Hostname is:  linuxtb3
IP address is: 192.168.1.xx

Why does this command returns this answer?

$ ssh user_name@192.168.1.xx "bash -s" -- < scripts/machine-info.sh
-bash: scripts/machine-info.sh: No such file or directory
  • Do you have a copy of the script (in the same location) on the local machine? – ctrl-alt-delor Jul 25 at 11:22
2

In your command

ssh user_name@192.168.1.xx "bash -s" -- < scripts/machine-info.sh

the redirection from scripts/machine-info.sh happens locally. It's a redirection into the ssh command and the data would end up at the standard input of the remote bash -s process (if the file had existed locally, but it doesn't, which is why you get an error).

In the other examples you show, the script is accessed on the remote machine.

For example, in

ssh user_name@192.168.1.xx 'bash -s -- < scripts/machine-info.sh'

the redirection is part of the command executed on the remote machine due to the single quotes around the command string.

  • I found it out, the command will work ssh user_name@192.168.1.xx "bash -s" -- < scripts/machine-info.sh will work if there is a script at the local machine. – klaus Jul 25 at 9:46
  • 1
    @klaus Yes, this is what I mentioned. – Kusalananda Jul 25 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.