zoukankan      html  css  js  c++  java
  • 远程重启linux主机的几种方法

    (转自http://www.cnblogs.com/read-the-spring-and-autumn-annals-in-night/p/3977102.html


    方法一,在终端上利用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 0]
    set PASSWORD [lindex $argv 1]
    set timeout 30
    
    spawn ssh root@$RHOST 'reboot'
    
    expect {
            "yes/no" {send "yes
    ";exp_continue}
            "password" {send "$PASSWORD
    "}
            timeout {exit 1}
    }
    expect eof
    exit 0
    
    
    调用时,参数为远程主机IP和密码,如 expect test.expect 192.168.8.128 123


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

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




  • 相关阅读:
    if判断语句和循环语句
    列表,元祖,字典的详细概述
    day10
    day09
    day08
    java---基本程序设计总结
    day07
    day06
    day05
    day04
  • 原文地址:https://www.cnblogs.com/read-the-spring-and-autumn-annals-in-night/p/12042005.html
Copyright © 2011-2022 走看看