gpt4 book ai didi

perl - Perl Net::SSH::Perl不加载我的环境变量与通过SSH连接

转载 作者:行者123 更新时间:2023-12-02 14:25:52 25 4
gpt4 key购买 nike

我的问题是通过Net::SSH::Perl连接vs通过SSH连接。
我的shell变量(命令:export)不一样。

这个事实使我无法执行依赖于shell env vars的用户脚本。

例如:

如果我通过perl(Net::SSH::Perl)执行命令:“export”,我得到:

MAIL=/var/mail/username
PATH=/usr/local/bin:/bin:/usr/bin
PWD=/username
SHELL=/bin/ksh
SSH_CLIENT='myIPAddress 1022 22'
SSH_CONNECTION='myIPAddress 1022 remoteIPAddress 22'
USER=myusername

通过常规的ssh连接执行同一命令时,我得到了42行ENV VARS。

其他例子:

如果我通过perl(Net::SSH::Perl)执行命令:“tty”我得到:
not a tty

通过常规的ssh连接执行相同的命令时,我得到:
/dev/pts/3

我在这里想念什么?

最佳答案

对于环境变量,听起来好像没有获取~/.bashrc。您应该可以自己获取它:

$ssh->cmd(". ~/.bashrc");

对于终端,不需要为许多任务分配 pty ,因此对于非交互式 shell 程序通常不需要这样做。但是,在创建ssh对象时,您可以传递 use_pty选项来告诉它创建 pty

来自 Net::SSH::Perl documentation:

use_pty

Set this to 1 if you want to request a pseudo tty on the remote machine. This is really only useful if you're setting up a shell connection (see the shell method, below); and in that case, unless you've explicitly declined a pty (by setting use_pty to 0), this will be set automatically to 1. In other words, you probably won't need to use this, often.

The default is 1 if you're starting up a shell, and 0 otherwise.

关于perl - Perl Net::SSH::Perl不加载我的环境变量与通过SSH连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3665496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com