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

ssh root@192.168.8.128 'reboot'

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

ssh root@192.168.8.128 bash <

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\r";exp_continue}

"password" {send "$PASSWORD\r"}

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

GitHub 加速计划 / li / linux-dash
13
2
下载
A beautiful web dashboard for Linux
最近提交(Master分支:4 个月前 )
186a802e added ecosystem file for PM2 5 年前
5def40a3 Add host customization support for the NodeJS version 5 年前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐