簡體   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