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 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件