方法一,在终端上利用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"yesr";exp_continue}
"password"{send"$PASSWORDr"}
timeout{exit 1}
}
expect eof
exit 0
调用时,参数为远程主机IP和密码,如expect test.expect 192.168.8.128 123
至于echo+sleep+|的方式,作为一个菜鸟,后面有时间再研究下
附:在linux系统上重启远程windows系统
下一篇:没有了