Edit_No.3 2019-12-31 13:37 采纳率: 0%
浏览 543

利用Linux的shell脚本sshWindows执行命令不成功

写了一个自动备份数据库的脚本,但每天查看结果都比较麻烦,就想写一个自动提示的脚本,而且是从虚机的linux直接发送提示到物理机的Windows,利用msg弹窗,具体脚本如下:

#!/usr/bin/expect
set timeout 30
set host "192.168.104.223"
set username "administrator"
set password "123"

spawn ssh $username@$host
expect "*password*" {send "$password\r"}
expect "*Administrator*" {send "cmd\r"}
expect "*Administrator*" {send "msg /server:$host * 已完成昨日MySQL数据库备份\r"}
expect "*Administrator*" {send "exit\r"}
expect "*Administrator*" {send "exit\r"}
expect "*Administrator*" {send "exit\r"}

如果我根据脚本的步骤手动去敲命令,物理机的Windows可以正常出现提示框,但写入到脚本之后就不行了,也不知道具体原因是什么,执行后如下所示:

[root@test_server shell]# ./windowspasswd.sh 
spawn ssh administrator@192.168.104.223

                            ****USAGE WARNING****

This is a private computer system. This computer system, including all
related equipment, networks, and network devices (specifically including
Internet access) are provided only for authorized use. This computer system
may be monitored for all lawful purposes, including to ensure that its use
is authorized, for management of the system, to facilitate protection against
unauthorized access, and to verify security procedures, survivability, and
operational security. Monitoring includes active attacks by authorized entities
to test or verify the security of this system. During monitoring, information
may be examined, recorded, copied and used for authorized purposes. All
information, including personal information, placed or sent over this system
may be monitored.

Use of this computer system, authorized or unauthorized, constitutes consent
to monitoring of this system. Unauthorized use may subject you to criminal
prosecution. Evidence of unauthorized use collected during monitoring may be
used for administrative, criminal, or other adverse action. Use of this system
constitutes consent to monitoring for these purposes.


administrator@192.168.104.223's password: 
Last login: Tue Dec 31 13:27:54 2019 from 192.168.104.223
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

D:\OpenSSH\home\Administrator>cmd
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

D:\OpenSSH\home\Administrator>msg /server:192.168.104.223 * 已完成昨日MySQL数据库备份


按脚本来走的话,最后Windows应该是成功出现弹窗,同时命令行退回到Linux才对啊。但实际到上面哪里就卡住不动了,也没有弹窗,也没有退回Linux。

  • 写回答

1条回答 默认 最新

  • 空白如空 2019-12-31 13:58
    关注

    结尾加个
    expect eof
    看看

    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突