通过 Telnet 从 Debian 到 Windows 执行远程命令 [英] Execute remote commands from Debian to Windows via Telnet

查看:26
本文介绍了通过 Telnet 从 Debian 到 Windows 执行远程命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 Debian 远程执行 Windows 中的命令行.为此,我尝试使用下面的 bash 脚本.使用 expect 工具,它包括通过 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
"
expect "password:"
send "$password
"
expect "C:UsersAdministrateur>"
send "$cmd
"

telnet 连接已经建立.但是,命令行没有被执行.

The telnet connection is well established. But, the command line is not executed.

谁能告诉我我的脚本有什么问题?

Could someone tell me what is wrong with my script?

推荐答案

只要在末尾多加一个expect语句,如下,

Just add one more expect statement at the end, like as follows,

send "$cmd
"
expect "C:UsersAdministrateur>"

基本上,expect 将使用两个可行的命令,例如 sendexpect.如果使用 send,那么之后必须有 expect(在大多数情况下).(反之亦然不是强制性的)

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)

这是因为如果不这样做,我们将错过生成过程中发生的事情,因为 expect 会假设您只需要发送一个字符串值,而不期待会话中的任何其他内容.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆