所以我在meteor.js项目中使用simple-ssh与远程服务器一起工作。 有什么办法可以将本地变量发送到服务器吗?也许像是
name = "dir";
ssh
.exec( 'mkdir' + name , {
out: console.log.bind(console)
})
答案 0 :(得分:0)
将其保存在本地计算机上作为文件script.sh ...它使用ssh在远程主机上执行内联bash脚本
#!/bin/bash
echo REMOTE_IP $REMOTE_IP
# ...
IFS='' read -r -d '' SSH_COMMAND_01 <<'EOT'
# ... top of inline bash script
echo "These commands will be run on remote host REMOTE_IP
echo "They are executed by: $( whoami )"
set -o errexit
echo put your commands here
echo can put your data inline here to get dealt with on remote box
echo some-local-data > /remoteuser/data_remotefile
echo now remote host has file containing data populated locally
# ... bottom of inline bash script
EOT
echo
echo now that we have defined the SSH_COMMAND_01 now execute it using ssh
echo
ssh remoteuser@${REMOTE_IP} "${SSH_COMMAND_01}"
一旦你创建了ssh密钥对并将公钥文件放在你的远程主机上并使用你的ssh填充你的本地环境,你就可以在本地执行上面的文件,这将跳转到远程主机并执行在开始EOT和结束EOT之间
本地终端中的使用远程服务器的域名或Internet地址填充此环境变量
export REMOTE_IP=123.45.678.019 # this defines remote box
chmod +x script.sh # make it executable
script.sh # launch it on your local box
与以上脚本分开以下内容可用于将文件从框A安全地复制到框B
#!/bin/bash
echo REMOTE_IP $REMOTE_IP
echo
echo now copy files from local to remote host
echo
sftp remoteuser@${REMOTE_IP} << STENSEOF
put ${localA_datafile1} /remoteuser/remoteB_datafile1
put ${localA_datafile2} /remoteuser/remoteB_datafile2
STENSEOF
答案 1 :(得分:0)
我找到了一种方法 -
var name = "name1";
ssh
.exec('mkdir ' + name + ' , {
out: console.log.bind(console)
})
这对我很有用
答案 2 :(得分:0)
默认情况下OpenSSH使用名称中的LC_导出每个变量,
创建类似这样的内容export LC_FRUIT="banana"
然后ssh user @ server,并打印此变量echo $LC_FRUIT