51Testing软件测试论坛

标题: 利用Linux的shell脚本sshWindows执行命令不成功 [打印本页]

作者: 测试积点老人    时间: 2020-1-2 11:20
标题: 利用Linux的shell脚本sshWindows执行命令不成功
利用Linux的shell脚本sshWindows执行命令不成功
写了一个自动备份数据库的脚本,但每天查看结果都比较麻烦,就想写一个自动提示的脚本,而且是从虚机的linux直接发送提示到物理机的Windows,利用msg弹窗,具体脚本如下:

  1. <p>#!/usr/bin/expect
  2. set timeout 30
  3. set host "192.168.104.223"
  4. set username "administrator"
  5. set password "123"</p><p>spawn ssh <a href="mailto:$username@$host">$username@$host</a>
  6. expect "*password*" {send "$password\r"}
  7. expect "*Administrator*" {send "cmd\r"}
  8. expect "*Administrator*" {send "msg /server:$host * 已完成昨日MySQL数据库备份\r"}
  9. expect "*Administrator*" {send "exit\r"}
  10. expect "*Administrator*" {send "exit\r"}
  11. expect "*Administrator*" {send "exit\r"}</p><p>如果我根据脚本的步骤手动去敲命令,物理机的Windows可以正常出现提示框,但写入到脚本之后就不行了,也不知道具体原因是什么,执行后如下所示:</p><p>[root[url=home.php?mod=space&uid=202723]@test_server[/url] shell]# ./windowspasswd.sh
  12. 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
  13. related equipment, networks, and network devices (specifically including
  14. Internet access) are provided only for authorized use. This computer system
  15. may be monitored for all lawful purposes, including to ensure that its use
  16. is authorized, for management of the system, to facilitate protection against
  17. unauthorized access, and to verify security procedures, survivability, and
  18. operational security. Monitoring includes active attacks by authorized entities
  19. to test or verify the security of this system. During monitoring, information
  20. may be examined, recorded, copied and used for authorized purposes. All
  21. information, including personal information, placed or sent over this system
  22. may be monitored.</p><p>Use of this computer system, authorized or unauthorized, constitutes consent
  23. to monitoring of this system. Unauthorized use may subject you to criminal
  24. prosecution. Evidence of unauthorized use collected during monitoring may be
  25. used for administrative, criminal, or other adverse action. Use of this system
  26. constitutes consent to monitoring for these purposes.</p><p>
  27. <a href="mailto:administrator@192.168.104.223's">administrator@192.168.104.223's</a> password:
  28. Last login: Tue Dec 31 13:27:54 2019 from 192.168.104.223
  29. Microsoft Windows [版本 6.1.7601]
  30. 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。</p><p>D:\OpenSSH\home\Administrator>cmd
  31. Microsoft Windows [版本 6.1.7601]
  32. 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。</p><p>D:\OpenSSH\home\Administrator>msg /server:192.168.104.223 * 已完成昨日MySQL数据库备份
  33. 按脚本来走的话,最后Windows应该是成功出现弹窗,同时命令行退回到Linux才对啊。但实际到上面哪里就卡住不动了,也没有弹窗,也没有退回Linux。</p>
复制代码



作者: jingzizx    时间: 2020-1-3 12:06
权限是否正确
作者: bellas    时间: 2020-1-3 13:50
权限是否正确
作者: litingting0214    时间: 2020-1-3 16:53
应该是权限不够导致,先排查一下这个原因
作者: 你好浮戈    时间: 2020-1-3 16:55
权限不够,增加权限




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2