6

I have /root/test.sh on a remote server, which has the following content:

#!/bin/bash
date

On the remote server, I get the following output:

# ./test.sh
Fri Dec 18 07:41:10 EST 2015

# bash <(cat /root/test.sh)
Fri Dec 18 07:41:23 EST 2015

However, if I try to run the same commands from my local machine, I get the following result:

$ ssh root@remote_server /root/test.sh
Fri Dec 18 07:44:32 EST 2015

$ ssh root@remote_server bash <(cat /root/test.sh)
cat: /root/test.sh: No such file or directory
bash: /dev/fd/63: No such file or directory

So what's the problem of the last run? You might find it weird to run a script like this bash <(cat /root/test.sh). The reason I did it is because it is a simplified version of my real situation. My real code is to download a Bash script from the Internet and run it locally. I have a lot of machines to run, with different parameters, so I'm trying to run them from my local computer.

  • 1
    Try ssh root@remote_server /bin/cat test.sh , for the simplified version. – Hastur Dec 18 '15 at 13:04
  • 1
    This is actually pretty similar to unix.stackexchange.com/questions/248345/… and is more-or-less suffering from the same problem I think. You don't really need process substitution as you might see from the other question – Eric Renouf Dec 18 '15 at 13:27
13

You can't pass file descriptors like this over ssh. <(...) construction creates virtual files on your system and it does not have a meaning when executing on remote system.

If you really want to use it, put it into the quotes, which will evaluate on the remote system, if you have bash there

ssh root@remote_host "bash <( cat /root/test.sh )"
4

My suggestion is to do a script on the remote host (/root/test.sh) make it executable (chmod u+x /root/test.sh) and run in the following way

ssh root@remote_server /bin/bash -c  /root/test.sh

About /bin/bash: /dev/fd/63: No such file or directory
You can read reasons on this answer [1].

Note:
Take the good habit to use the full path (/bin/bash) instead of only the command name (bash) to avoid unneeded security risks [2].


Another way should be

ssh root@remote_server << EOF
cat  /root/test.sh
# whatever else
EOF

It will execute each line until the second EOF... you can do your variants about it...

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.