方法一,在终端上利用ssh,不登录远程主机,直接发送重启命令

ssh root@192.168.8.128 'reboot'

方法二,在终端上利用ssh和here document

ssh root@192.168.8.128 bash <<EOF
reboot
EOF

这种方式在reboot的位置其实可以执行多条其他的命令,说到这儿,还有一种有意思的用法

ssh root@192.168.8.128 bash < test.sh

这样可以在远程主机上执行本地写好的一个脚本文件

方法三,通过expect脚本自动执行,以下是我写的一个expect脚本,test.expect

#!/usr/bin/expect

set RHOST [lindex $argv ]
set PASSWORD [lindex $argv ]
set timeout spawn ssh root@$RHOST 'reboot' expect {
"yes/no" {send "yes\r";exp_continue}
"password" {send "$PASSWORD\r"}
timeout {exit }
}
expect eof
exit

调用时,参数为远程主机IP和密码,如 expect test.expect 192.168.8.128 123

至于echo+sleep+|的方式,作为一个菜鸟,后面有时间再研究下

附:在linux系统上重启远程windows系统

net rpc shutdown -r -f -I 192.168.8.156 -U administrator%

最新文章

  1. Symbol not found for architecture arm64 错误
  2. UI控件
  3. C/C++中const的用法 分类: C/C++ 2015-07-05 00:43 85人阅读 评论(0) 收藏
  4. SHA1算法
  5. IDEA之创建不了.java文件解决
  6. 分布式Apache ZooKeeper-3.4.6集群安装
  7. UESTC 883 方老师与两个串 --二分搜索+DP
  8. hdu 4883 思维题
  9. 在Vim里使用gtags-cscope
  10. Hadoop集群系类文章
  11. Ubuntu 14.04 dnw配置
  12. 64位ubuntu编译32位程序
  13. Twitter Bootstrap JavaScript插件
  14. Unity 5 Stats窗口
  15. 导出Excel(Ext 前台部分)
  16. 【Java】 剑指offer(44) 连续子数组的最大和
  17. 性能测试-9.Controller功能介绍
  18. Oracle EBS AR 收款取数
  19. 白话 Ruby 与 DSL 以及在 iOS 开发中的运用
  20. SQLSERVER SQL备份还原代码C#

热门文章

  1. iphone/ipad实现自定义的开关UISwitch(continuous,clipsToBounds,userInteractionEnabled属性)
  2. Linux之Samba的配置
  3. dojo 十二 rest
  4. 5.cadence原理图上[原创]
  5. js和 jquery对象
  6. BZOJ 1047 理想的正方形(单调队列)
  7. ORACLE EBS R12 - 寄售功能知多少
  8. Oracle数据库之一
  9. 将js对象转为json对象属性加上引号
  10. 安装CouchbaseClient的过程中提示 Error 1935.An error occurred during the installation of assembly;Error:-1603 fatal error during installation