SSH自动登陆服务器--ARM linux
2017-03-06 10:45
197 查看
因为需要用到ssh自动登陆到远程服务器并执行相关命令,但是ssh不支持重定向和管道方式,所以只能使用expect,这里我使用的是ARM9的平台所以需要移植expect:
由于expect是基于tcl语言的,所以移植expect前,需先交叉编译tcl
1、下载地址
tcl:http://www.tcl.tk/software/tcltk/download.html
expect:http://sourceforge.net/projects/expect/files/latest/download?source=files
连接-移植过程
shell 脚本:
#!/usr/bin/expect #-------------------------------------------------- about us # product: SSH autologin # Author:horse # Last Modified: 2017/3/3 # version:001 # user:this script to shutdown remote linux(unix) machine set ipaddr [lindex $argv 0] set loginuser [lindex $argv 1] set loginpass [lindex $argv 2] set command [lindex $argv 3] #set ipaddr 192.168.107.109 #set loginuser "root" #set loginpass "12345678" set timeout 300 set cmd_prompt "]#|~$]?" puts "$ipaddr, $loginuser, $loginpass, $command" #-------------------------------------------------- login by ssh spawn ssh $loginuser@$ipaddr set timeout 2 expect { -re "*yes/no*" { send "yes\r" } "*password:*" { send "${loginpass}\r" } -re "Permission denied, please try again." { exit } -re "Connection refused" { exit } timeout { exit } eof { exit } } #---------------------------------------------------- now,we do some commands expect "*$" send "$command\r" exec usleep 300 send "exit\r" exit
远程重启系统可以使用以下命令
./ssh.sh 192.168.107.109 root 12345678 reboot\&
相关文章推荐
- Linux多台服务器共用密钥ssh自动登陆
- iTerm2 结合 Linux expect 实现 ssh 自动登陆, 通过跳板机登录服务器内网功能
- linux 服务器多台ssh无密码自动登陆
- shell脚本ssh自动登陆服务器
- sshpass实现ssh自动输入密码登陆服务器
- Linux多台服务器共用密钥ssh自动登陆
- 使用public/private key让putty(ssh)自动登录(以及linux上使用密钥做ssh自动登陆)
- 让2K与XP、win2003服务器自动登陆技巧
- 使用Putty密钥验证自动登陆服务器
- 不输入密码自动通过 SSH 方式登录服务器
- shell脚本实现无密码交互的SSH自动登陆
- 使用SSH证书登陆远程服务器
- 使用expect实现ssh自动输入密码,从而自动登陆Linux
- 用expect实现ssh自动登录对服务器进行批量管理
- 【解决】ssh登陆远程服务器后,gcc编译出现乱码问题
- 使用SSH证书(不要密码)登陆远程服务器
- 用expect实现ssh自动登录对服务器进行批量管理
- 用expect实现ssh自动登录对服务器进行批量管理
- 不输入密码自动通过SSH方式登录服务器
- 服务器不登陆就自动拨号ADSL上网的方法