测试积点老人 发表于 2020-1-2 11:20:00

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

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

<p>#!/usr/bin/expect
set timeout 30
set host "192.168.104.223"
set username "administrator"
set password "123"</p><p>spawn ssh <a href="mailto:$username@$host">$username@$host</a>
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"}</p><p>如果我根据脚本的步骤手动去敲命令,物理机的Windows可以正常出现提示框,但写入到脚本之后就不行了,也不知道具体原因是什么,执行后如下所示:</p><p>@test_server shell]# ./windowspasswd.sh
spawn ssh <a href="mailto:administrator@192.168.104.223">administrator@192.168.104.223</a></p><p>                            ****USAGE WARNING****</p><p>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.</p><p>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.</p><p>
<a href="mailto:administrator@192.168.104.223's">administrator@192.168.104.223's</a> password:
Last login: Tue Dec 31 13:27:54 2019 from 192.168.104.223
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。</p><p>D:\OpenSSH\home\Administrator>cmd
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。</p><p>D:\OpenSSH\home\Administrator>msg /server:192.168.104.223 * 已完成昨日MySQL数据库备份
按脚本来走的话,最后Windows应该是成功出现弹窗,同时命令行退回到Linux才对啊。但实际到上面哪里就卡住不动了,也没有弹窗,也没有退回Linux。</p>

jingzizx 发表于 2020-1-3 12:06:42

权限是否正确

bellas 发表于 2020-1-3 13:50:12

权限是否正确

litingting0214 发表于 2020-1-3 16:53:12

应该是权限不够导致,先排查一下这个原因

你好浮戈 发表于 2020-1-3 16:55:13

权限不够,增加权限
页: [1]
查看完整版本: 利用Linux的shell脚本sshWindows执行命令不成功