is it possible to use variables in remote ssh command?

I'd like to execute several commands in sequence on a remote machine, and some of the later commands depend on earlier ones. In the simplest possible example I get this: ssh my_server "echo this is my_server; abc=2;" this is my_server abc=2: Command not found. ssh my_server "echo this is my_server; abc=2; echo abc is $abc" abc: undefined variable For a bit of background info, what I actual

是否有可能在远程SSH命令中使用变量?

我想在远程机器上按顺序执行几个命令,而后面的一些命令依赖于以前的命令。 在最简单的例子中,我得到了这个: ssh my_server "echo this is my_server; abc=2;" this is my_server abc=2: Command not found. ssh my_server "echo this is my_server; abc=2; echo abc is $abc" abc: undefined variable 对于一些背景信息,我真正想做的是拼凑一条路径并启动一个Java应用程序: ssh my_server 'nohup sh -c "( ( echo this i

Execute Bash script stored in a file over SSH

Say I have the following Bash script stored in the file foo.sh : #!/bin/bash echo foo Without having to scp the file, how could I execute the script stored in foo.sh on a remote machine? I have tried the following (with a few variations) to no success: $ ssh root@remote eval `cat foo.sh` eval `cat foo.sh` seems to expand to eval #!/bin/bash echo foo here ssh root@MachineB 'bash -s' < lo

通过SSH执行存储在文件中的Bash脚本

假设我有以下Bash脚本存储在文件foo.sh : #!/bin/bash echo foo 无需scp文件,我怎么能执行存储在远程机器上foo.sh的脚本? 我尝试了以下(有一些变化),但没有成功: $ ssh root@remote eval `cat foo.sh` eval `cat foo.sh`似乎扩展到eval #!/bin/bash echo foo这里 ssh root@MachineB 'bash -s' < local_script.sh 我从该线程得到它:如何使用SSH在远程计算机上运行shell脚本? 在接受的答案中,我看到: 我想

UNIX ssh script, running commands on remote server

I would like to create a script that automatically logs into a remote server and grabs a file on the server. The script already logs into the server however the commands are not run on that machine. Once I disconnect from the remote server, the commands are run on the client machine. !/bin/sh ssh -o PreferredAuthentications=publickey brjones@server.com cd ~/folder "i would like to grab file an

UNIX ssh脚本,在远程服务器上运行命令

我想创建一个自动登录到远程服务器并在服务器上抓取文件的脚本。 脚本已经登录到服务器,但是该命令不在该机器上运行。 一旦我从远程服务器断开连接,命令就会在客户机上运行。 !/bin/sh ssh -o PreferredAuthentications=publickey brjones@server.com cd ~/folder "i would like to grab file and copy it to client machines folder" 编辑:我不知道你是否注意到,但我用密码连接到远程服务器使用ssh和keygeneration。

how to run a script file remotely using ssh

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` 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 comman

如何使用ssh远程运行脚本文件

我想远程运行脚本。 但系统无法识别路径。 它抱怨说“没有这样的文件或目录”我是否正确使用它? ssh kev@server1 `./test/foo.sh` 反引号将在本地shell上运行该命令并将结果放在命令行上。 你说的是'执行./test/foo.sh然后传递输出,就好像我在这里命令行输入'一样。 尝试以下命令,并确保从远程计算机上的主目录到您的脚本的路径。 ssh kev@server1 './test/foo.sh' 另外,该脚本必须位于远程计算机上。 它所

Run ssh and immediately execute command

This question already has an answer here: Can I ssh somewhere, run some commands, and then leave myself a prompt? 4 answers ssh -t 'command; bash -l' 将执行该命令,然后在完成时启动登录shell。 You can use the LocalCommand command-line option if the PermitLocalCommand option is enabled: ssh username@hostname -o LocalCommand="tmux list-sessions" For more details about the availabl

运行ssh并立即执行命令

这个问题在这里已经有了答案: 我可以在什么地方sshsh,运行一些命令,然后给我一个提示? 4个答案 ssh -t 'command; bash -l' 将执行该命令,然后在完成时启动登录shell。 如果启用PermitLocalCommand选项,则可以使用LocalCommand命令行选项: ssh用户名@主机名-o LocalCommand =“tmux list-sessions” 有关可用选项的更多详细信息,请参见ssh_config手册页。 这不是你想要的,但我发现它在类似情况下很有用。 我

rsync: how can I configure it to create target directory on server?

I would like to rsync from local computer to server. On a directory that does not exist, and I want rsync to create that directory on the server first. How can I do that? If you have more than the last leaf directory to be created, you can either run a separate ssh ... mkdir -p first, or use the --rsync-path trick as explained here : rsync -a --rsync-path="mkdir -p /tmp/x/y/z/ && rs

rsync:我如何配置它以在服务器上创建目标目录?

我想从本地计算机到服务器的rsync 。 在一个不存在的目录上,我希望rsync首先在服务器上创建该目录。 我怎样才能做到这一点? 如果您创建的最后一个叶子目录不止一个,您可以先运行单独的ssh ... mkdir -p ,或者使用--rsync-path技巧,如下所述: rsync -a --rsync-path="mkdir -p /tmp/x/y/z/ && rsync" $source user@remote:/tmp/x/y/z/ 或者按照Tony的建议使用--relative选项。 在这种情况下,您只需指定必

What is the cleanest way to ssh and run multiple commands in Bash?

I already have an ssh agent set up, and I can run commands on an external server in Bash script doing stuff like: ssh blah_server "ls; pwd;" Now, what I'd really like to do is run a lot of long commands on an external server. Enclosing all of these in between quotation marks would be quite ugly, and I'd really rather avoid ssh'ing multiple times just to avoid this. So, is there a

在Bash中ssh和运行多个命令最干净的方法是什么?

我已经建立了一个ssh代理,并且我可以在Bash脚本的外部服务器上运行命令,执行如下操作: ssh blah_server "ls; pwd;" 现在,我真正想做的是在外部服务器上运行很多长命令。 将所有这些用引号括起来都是相当难看的,为避免这种情况,我宁愿多次避免ssh'ing。 那么,我有办法一次性完成这个任务吗? 我正在寻找的东西沿线: ssh blah_server ( ls some_folder; ./someaction.sh; pwd; ) 基本上,只要干净,

Need to execute a shell script in different unix servers

This question already has an answer here: How to use SSH to run a shell script on a remote machine? 11 answers I would suggest 4 different ways of doing it, 1. The easiest way : configure space cleanup script in crontab 2. Call script in remote servers from one server via ssh . see this link how-to-use-ssh-to-run-a-shell-script-on-a-remote-machine 3. Run a script which keep on looking

需要在不同的Unix服务器上执行一个shell脚本

这个问题在这里已经有了答案: 如何使用SSH在远程机器上运行shell脚本? 11个答案 我会建议4种不同的做法, 1.最简单的方法:在crontab配置空间清理脚本 2.通过ssh从一台服务器调用远程服务器中的脚本。 请参阅此链接how-to-use-ssh-to-run-a-shell-script-on-a-remote-machine 3.运行一个script ,在某个位置继续查找status/trigger file (虚拟文件),并在需要时将虚拟文件(ftp,scp等)从一台服务器推送到该特

bash heredoc gets corrupted(randomly) when pasted to ssh terminal

This question already has an answer here: How to use SSH to run a shell script on a remote machine? 11 answers 尝试按照这里所建议的ssh remoteuser@ip.address.of.server 'bash -s' < scriptfile.sh

bash heredoc在粘贴到ssh终端时会被(随机)破坏

这个问题在这里已经有了答案: 如何使用SSH在远程机器上运行shell脚本? 11个答案 尝试按照这里所建议的ssh remoteuser@ip.address.of.server 'bash -s' < scriptfile.sh

run a local script as root on remote server

This question already has an answer here: How to use SSH to run a shell script on a remote machine? 11 answers Ok, then why do you "echo mypassword" ? Can't you add your SSH account to the sudoers file with NOPASSWD ? From man sudoers : authenticate If set, users must authenticate themselves via a password (or other means of authentication) before

在远程服务器上以root身份运行本地脚本

这个问题在这里已经有了答案: 如何使用SSH在远程机器上运行shell脚本? 11个答案 好的,那么你为什么“回声mypassword”? 你不能使用NOPASSWD将你的SSH帐户添加到sudoers文件中吗? 从man sudoers : authenticate If set, users must authenticate themselves via a password (or other means of authentication) before they may run commands. This default may be ov