繁体   English   中英

在终端上的Perl打印输出中反引号

[英]backtick in Perl printing output on terminal

我试图获取变量中命令的输出,并检查其是否与其他变量匹配。

   $login1=`ssh ****************** date`;

手动键入此命令时,将提示您输入“ Password:”。 当我从脚本运行它时,它正在调用该命令并打印该提示以等待用户输入,但是我不需要它。 我只需要获取该输出并进行比较

     if($login1=~ /Password:/)
            {   
              print " yes";
            }
         else
              {
                print "No ";
               }

但是,该脚本仅在密码提示时停止。 请给我建议如何实现这一目标。

您可能要查看ssh-f标志:

  -f Requests ssh to go to background just before command execution. This is useful if ssh is going to ask for passwords or passphrases, but the user wants it in the background. This implies -n. The recommended way to start X11 programs at a remote site is with something like ssh -f host xterm. 

如果要避免使用密码,请设置没有密码短语的公共/私人密钥对(危险,但是比在脚本中放置密码要危险得多),然后将公共密钥复制到远程站点。 IIRC,它是这样的:

localhost $ ssh-keygen -b 2048 -t ecdsa -N '' -f ./datekey
localhost $ scp ./datekey.pub remotehost:/tmp
localhost $ ssh remotehost
(login)
remotehost $ cat /tmp/datekey.pub >> ~/.ssh/authorized_keys
remotehost $ logout

localhost $ ssh -i ./datekey remotehost date

确保将./datekey存储在其他用户根本无法访问的位置-甚至没有读取权限。


如果您只是想检测,则可能只需要提供EOF即可继续前进:

$login1=`ssh ****************** date < /dev/null`;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM