通过Telnet执行从Debian到Windows的远程命令 [英] Execute remote commands from Debian to Windows via Telnet
问题描述
我正在从Debian远程执行Windows中的命令行。为此,我尝试使用下面的bash脚本。使用期望工具,它包括通过 telnet 连接到远程服务器,输入用户名和密码值并发送所需的命令行。
I am working on remotely executing a command line in Windows from Debian. For that, I tried to use the bash script below. Using the expect tool, it consists in connecting via telnet to the remote server, entering username and password values and sending the command line desired.
#!/usr/bin/expect
set timeout 20
set name 192.168.1.46
set user Administrateur
set password MSapp/*2013
set cmd "TASKKILL /F /IM Tomcat6.exe"
spawn telnet 192.168.1.46
expect "login:"
send "$user\r"
expect "password:"
send "$password\r"
expect "C:\Users\Administrateur>"
send "$cmd\r"
telnet连接已建立。但是,命令行没有执行。
The telnet connection is well established. But, the command line is not executed.
有人可以告诉我我的脚本怎么了吗?
Could someone tell me what is wrong with my script?
推荐答案
只需在末尾再添加一个期望
语句,如下所示,
Just add one more expect
statement at the end, like as follows,
send "$cmd\r"
expect "C:\Users\Administrateur>"
基本上,期望
可以在两个可行的情况下工作发送
和期望
之类的命令。如果使用了 send
,则在大多数情况下必须具有期望
。 (反之则不是强制性的)
Basically, expect
will work with two feasible commands such as send
and expect
. If send
is used, then it is mandatory to have expect
(in most of the cases) afterwards. (while the vice-versa is not required to be mandatory)
这是因为没有这些,我们将错过生成过程中发生的期望
将假定您只需要发送一个字符串值,而不希望会话中有其他任何内容。
This is because without that we will be missing out what is happening in the spawned process as expect
will assume that you simply need to send one string value and not expecting anything else from the session.
这篇关于通过Telnet执行从Debian到Windows的远程命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!