如何在 telnet 上Linux主机后执行命令
2个回答
展开全部
1如何在 telnet 上Linux
主机后远程执行主机上的shell脚本
http://www.autoitx.com/archiver/tid-22151.html
从 Windows telnet 到 Linux,建立主机与设备的通信,这是典型的嵌入式测试环境。 我的问题代表了一类人的需求。
[url]http://www.autoitscript.com/forum/topic/82393-telnet-in-background/page__p__590023#entry590023[/url] 这个4楼的帖子具有相当的参考价值。又是一种方法。稍作修改和封装,如下:[code] ;Using native socket connection to simulates a TELNET connection to communicate with Linux machine for sending commands and receiving info from it
$port = 23 $user = "root" $passwd = "xxxxxx" TCPStartup() $socket = TCPConnect($host, $port) If $socket = -1 Then MsgBox(48, "Error", "Connection fail!") Exit EndIf
Sleep(300) $ack = TCPRecv($socket, 150) If StringInStr($ack, "login") > 0 Then TCPSend($socket, $user & @CRLF) Sleep(500) TCPSend($socket, $passwd & @CRLF) Else MsgBox(48, "Error", "Cannot connect") Exit
EndIf
wait_cmd_prompt($socket) TCPSend($socket, $cmd1 & @CRLF) wait_cmd_prompt($socket) TCPSend($socket, $cmd2 & @CRLF) wait_cmd_prompt($socket) TCPCloseSocket($socket) TCPShutdown()
;================================================================================================ ;
Function Definition ;===================================================================================
============= ;Wait for desired command prompt character "#" before sending. Func wait_cmd_prompt($sk) Local $ack
Do
$ack = StringStripWS(TCPRecv($sk, 300), 2) Sleep(300) ;MsgBox(0,"",$ack) Until StringRight($ack, 1) = "#" ;MsgBox(0,"","out of loop") EndFunc[/code]不过,我一楼发的问题还没得到解决。 运行设备端(Linux环境)的脚本(shell脚本)远比远程命令控制来得可靠,因为这样Linux的一些环境变量是可继承的。 继续研究中。 minterz 发表于 2011-2-22 19:51 linxu下的bash脚本如果要远程启动 可以使用plink 使用ssh远程控制 xiehuahere 发表于 2011-2-23 12:11 谢谢楼上的,我试试。 另外,这样也行: TCPSend($socket, "/home/script.sh " & $param & @CRLF)
Posted 14 October 2008 - 09:19 PM Why not using native socket connections like following example. I am using this algorithm to communicate with my router (Linux machine) for
sending commands and receiving info from it. Be sure to replace specific information.
;BEGIN SCRIPT---------------------------------------------- ;simulates a TELNET connection Global $host, $port, $delay, $user, $pass, $sk, $ack
$host = "192.168.1.1" $port = 23
; miliseconds to wait before sending/receiving something $delay = 300 compensates network/internet delays $user = "" $pass = "" TCPStartup()
$sk = TCPConnect($host, $port) ;if invalid socket If $sk = -1 Then MsgBox(0, "", "Cannot connect")
Exit EndIf ; message from device
Sleep($delay) $ack = TCPRecv($sk, 150) TrayTip("", $ack, 10) ; verifying the correct answer If StringInStr($ack, "wl500gp login") >= 1 Then ; if the string is correct then we send user
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询