远程重启linux主机的几种方法
2024-08-22 02:05:36
方法一,在终端上利用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%
最新文章
- Symbol not found for architecture arm64 错误
- UI控件
- C/C++中const的用法 分类: C/C++ 2015-07-05 00:43 85人阅读 评论(0) 收藏
- SHA1算法
- IDEA之创建不了.java文件解决
- 分布式Apache ZooKeeper-3.4.6集群安装
- UESTC 883 方老师与两个串 --二分搜索+DP
- hdu 4883 思维题
- 在Vim里使用gtags-cscope
- Hadoop集群系类文章
- Ubuntu 14.04 dnw配置
- 64位ubuntu编译32位程序
- Twitter Bootstrap JavaScript插件
- Unity 5 Stats窗口
- 导出Excel(Ext 前台部分)
- 【Java】 剑指offer(44) 连续子数组的最大和
- 性能测试-9.Controller功能介绍
- Oracle EBS AR 收款取数
- 白话 Ruby 与 DSL 以及在 iOS 开发中的运用
- SQLSERVER SQL备份还原代码C#
热门文章
- iphone/ipad实现自定义的开关UISwitch(continuous,clipsToBounds,userInteractionEnabled属性)
- Linux之Samba的配置
- dojo 十二 rest
- 5.cadence原理图上[原创]
- js和 jquery对象
- BZOJ 1047 理想的正方形(单调队列)
- ORACLE EBS R12 - 寄售功能知多少
- Oracle数据库之一
- 将js对象转为json对象属性加上引号
- 安装CouchbaseClient的过程中提示 Error 1935.An error occurred during the installation of assembly;Error:-1603 fatal error during installation