如何将变量从本地服务器传递到远程服务器? [英] How do I pass a variable from my local server to a remote server?

查看:74
本文介绍了如何将变量从本地服务器传递到远程服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将变量从本地服务器(位置1)传递到远程服务器(位置2).该代码的目的是从预定义的位置从远程服务器复制文件.简单来说,我想使用预定义的路径将文件从location2复制到location1,其中location1在本地服务器上,而location2是远程服务器.参见代码段:

I am trying to pass a variable from my local server (location1) to a remote server (location2). The purpose of the code is to copy a file from the remote server from a predefined location. In simpler terms, I want to copy files from location2 to location1 using a predefined path where location1 is on the local server and location2 is a remote server. See the code segment:

 $location1=somewhere/on/local_server
 $location2=somewhere/on/remote_server

 sshpass -p "password" ssh username@74.11.11.11 'su -lc "cp -r $location2 $location1";'

我得到的错误是$ location1和$ location2都未定义.另外,我也不想手动键入位置路径,因为它们可以随时更改,如果手动进行更改,则很麻烦.

The error I get is that both $location1 and $location2 are undefined. Also, I DON'T want to manually type the location paths because they could change at any time and it would be a pain to change them in the code if done manually.

推荐答案

您可以这样做:

sshpass -p "password" ssh username@74.11.11.11 "su -lc \"cp -r $location2 $location1\""

这篇关于如何将变量从本地服务器传递到远程服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆