歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> Linux資訊 >> 更多Linux

Telnet到Sco unix執行並取得結果

前一段做了一個監控程序,觸發事件後實現telnet到Sco unix執行命令並取得命令結果,想了幾天終於完成,特和大家分享:

 

 

 

  一、安裝TelnetTool控件(提供下載)

  二、VFP代碼部分: 

       LOCAL telnet1        telnet1=CREATEOBJECT("Dart.Telnet.1")    Telnet1.Timeout = 100    Telnet1.TermType = "vt100"  False=.t.  True=.t.  vbCrLf=CHR(13)+CHR(10)    ** logfile = "Host" + HostIP + ".log"    ** Telnet1.Trace(logfile, False, True, vbCrLf + "---> ", vbCrLf + "<--- ")         thisform.AddLog(Tsys_kind,"正在連接主機 " + HostIP + " ..." + vbCrLf)             ok = Telnet1.Connect(HostIP, 23)     IF ok=""      thisform.AddLog(Tsys_kind,"銀聯前置["+HostIP+"]連接失敗!同銀聯中心鏈路無法檢查。")      thisform.showinfo("99","錯誤:銀聯前置連接失敗!")       thisform.warn       thisform.command4.Picture="deng3.gif"       thisform.command4.refresh        telnet1.close        RETURN     ELSE       telnet1.close       Telnet1.Timeout = 10000       Telnet1.Connect(HostIP, 23)             ENDIF           thisform.AddLog(Tsys_kind,"已連接" + vbCrLf)

    Data = ""

    Telnet1.Search (@Data, "login:")

     * thisform.AddLog( Tsys_kind,Data)

    Telnet1.Send(User_name + vbCrLf)    Data = ""

    Telnet1.Search(@Data, "PassWord:")    *  thisform.AddLog(Tsys_kind,Data)

    Telnet1.Send (User_pwd + vbCrLf)    Data = ""

    Telnet1.Search(@Data, ">")   *   thisform.AddLog(Tsys_kind,Data)

    Telnet1.Send ("su" + vbCrLf)    Telnet1.Search (@Data, "Password:")    *  thisform.AddLog(Tsys_kind,data)    Telnet1.Send(root_pwd + vbCrLf)    Telnet1.Search(@Data, "#")    * thisform.AddLog(Tsys_kind,Data)

    Telnet1.Send(shell_cmd + vbCrLf)    Telnet1.Search(@Data, "#")   * thisform.AddLog(Tsys_kind,data)

      ***************取出的數據

  ok = VAL(STREXTRACT(data,"/","/",3))

   IF ok>WP04 && Warn Point

  thisform.showinfo("01","★警告:銀聯中心網絡延時[9.234.12.21]!當前值:"+ALLTRIM(STR(ok,10,2))+"設定值:"+ALLTRIM(STR(WP04,10,2)))

  thisform.addlog(Tsys_kind,"★警告:銀聯中心網絡延時[9.234.12.21]!當前值:"+ALLTRIM(STR(ok,10,2))+"設定值:"+ALLTRIM(STR(WP04,10,2)))

  ......&&觸發事件

  ENDIF




Copyright © Linux教程網 All Rights Reserved