I want to run a script remotely. But the system doesn't recognize the path. It complains that "no such file or directory "Am i using it right?
我想远程运行一个脚本。但是系统不承认路径。它抱怨说“没有这样的文件或目录”,我使用它对吗?
ssh kev@server1 `./test/foo.sh`
6 个解决方案
#1
40
Backticks will run the command on the local shell and put the results on the command line. What you're saying is 'execute ./test/foo.sh and then pass the output as if I'd typed it on the commandline here'.
Backticks将在本地shell上运行该命令,并将结果放在命令行上。你说的是“执行”。/test/foo。然后传递输出,就像我在命令行输入的一样。
Try the following command, and make sure that thats the path from your home directory on the remote computer to your script.
尝试下面的命令,并确保从远程计算机上的主目录到脚本的路径。
ssh kev@server1 './test/foo.sh'
Also, the script has to be on the remote computer. What this does is essentially log you into the remote computer with the listed command as your shell. You can't run a local script on a remote computer like this (unless theres some fun trick I don't know).
另外,脚本必须在远程计算机上。它所做的就是将你的命令作为你的外壳进入远程计算机。你不能像这样在远程计算机上运行本地脚本(除非有一些我不知道的有趣的技巧)。
#2
121
What you can do is.
你能做的就是。
ssh user@host 'bash -s' < /path/script.sh
#3
1
I don't know if it's possible to run it just like that.
我不知道是否可以这样运行。
I usually first copy it with scp and then log in to run it.
我通常先用scp复制它,然后再登录来运行它。
scp foo.sh user@host:~
ssh user@host
./foo.sh
#4
0
Make the script executable by the user "Kev" and then remove the try it running through the command sh kev@server1 /test/foo.sh
让用户“Kev”执行脚本,然后删除通过命令sh kev@server1 /test/foo.sh运行的脚本。
#5
0
I was able to invoke a shell script using this command:
我可以使用这个命令调用一个shell脚本:
ssh ${serverhost} "./sh/checkScript.ksh"
of course checkScript.ksh
must exist in $HOME/sh
directory.
当然checkScript。ksh必须存在于$HOME/sh目录中。
#6
0
If you want to execute local script remotely without saving that script remotely you can do it like this:
如果您想要远程执行本地脚本,而不需要远程保存脚本,您可以这样做:
cat local_script.sh | ssh user@remotehost 'bash -'
works like a charm for me.
对我来说是一种魅力。
I do that even from Windows to Linux given that you have MSys installed on your Windows computer.
我甚至从Windows到Linux都这么做,因为你的Windows电脑上安装了MSys。
#1
40
Backticks will run the command on the local shell and put the results on the command line. What you're saying is 'execute ./test/foo.sh and then pass the output as if I'd typed it on the commandline here'.
Backticks将在本地shell上运行该命令,并将结果放在命令行上。你说的是“执行”。/test/foo。然后传递输出,就像我在命令行输入的一样。
Try the following command, and make sure that thats the path from your home directory on the remote computer to your script.
尝试下面的命令,并确保从远程计算机上的主目录到脚本的路径。
ssh kev@server1 './test/foo.sh'
Also, the script has to be on the remote computer. What this does is essentially log you into the remote computer with the listed command as your shell. You can't run a local script on a remote computer like this (unless theres some fun trick I don't know).
另外,脚本必须在远程计算机上。它所做的就是将你的命令作为你的外壳进入远程计算机。你不能像这样在远程计算机上运行本地脚本(除非有一些我不知道的有趣的技巧)。
#2
121
What you can do is.
你能做的就是。
ssh user@host 'bash -s' < /path/script.sh
#3
1
I don't know if it's possible to run it just like that.
我不知道是否可以这样运行。
I usually first copy it with scp and then log in to run it.
我通常先用scp复制它,然后再登录来运行它。
scp foo.sh user@host:~
ssh user@host
./foo.sh
#4
0
Make the script executable by the user "Kev" and then remove the try it running through the command sh kev@server1 /test/foo.sh
让用户“Kev”执行脚本,然后删除通过命令sh kev@server1 /test/foo.sh运行的脚本。
#5
0
I was able to invoke a shell script using this command:
我可以使用这个命令调用一个shell脚本:
ssh ${serverhost} "./sh/checkScript.ksh"
of course checkScript.ksh
must exist in $HOME/sh
directory.
当然checkScript。ksh必须存在于$HOME/sh目录中。
#6
0
If you want to execute local script remotely without saving that script remotely you can do it like this:
如果您想要远程执行本地脚本,而不需要远程保存脚本,您可以这样做:
cat local_script.sh | ssh user@remotehost 'bash -'
works like a charm for me.
对我来说是一种魅力。
I do that even from Windows to Linux given that you have MSys installed on your Windows computer.
我甚至从Windows到Linux都这么做,因为你的Windows电脑上安装了MSys。