expect使用ssh登录脚本
2012-11-21 12:51
211 查看
基础篇:
#!u/s+ SSH
spawn ssh -l root 10.10.10.24
# 等待响应,第一次登录往往会提示是否永久保存 RSA 到本机的 know hosts 列表中;等到回答后,在提示输出密码;之后就直接提示输入密码
expect "(yes/no)?" {
send "yes\r"
expect "password:"
send "123456\r"
} "password:" {send "123456\r"} "*host "
interact
# 这里使用了 interact 命令,使执行完程序后,用户可以在 $host 终端进行交互操作。
多用户登录,使用shell进行调用
#!/usr/bin/expect -f
set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 30
spawn ssh root@$ipaddress
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "$passwd\r" }
}
expect "*from*"
interact
~
shell调用脚本
#!/bin/bash
if [ $1 == 24 ];then
i='10.10.10.24'
j='123456'
fi
if [ $1 == 17 ];then
i='10.10.10.17'
j='1qaz2wsx'
fi
echo $i
echo $j
expect /home/shell/benchmark/login.exp $i $j
#!u/s+ SSH
spawn ssh -l root 10.10.10.24
# 等待响应,第一次登录往往会提示是否永久保存 RSA 到本机的 know hosts 列表中;等到回答后,在提示输出密码;之后就直接提示输入密码
expect "(yes/no)?" {
send "yes\r"
expect "password:"
send "123456\r"
} "password:" {send "123456\r"} "*host "
interact
# 这里使用了 interact 命令,使执行完程序后,用户可以在 $host 终端进行交互操作。
多用户登录,使用shell进行调用
#!/usr/bin/expect -f
set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 30
spawn ssh root@$ipaddress
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "$passwd\r" }
}
expect "*from*"
interact
~
shell调用脚本
#!/bin/bash
if [ $1 == 24 ];then
i='10.10.10.24'
j='123456'
fi
if [ $1 == 17 ];then
i='10.10.10.17'
j='1qaz2wsx'
fi
echo $i
echo $j
expect /home/shell/benchmark/login.exp $i $j
相关文章推荐
- ssh登录脚本 expect语言中使用awk
- Linux中使用expect脚本实现远程机器自动登录
- 使用ssh登录shell脚本远程调用
- ssh expect自动登录的脚本代码
- 无密钥登录的自动脚本实现(ssh-copy-id、expect免交互输入脚本)
- 使用expect实现ssh不输入密码登录远程服务器
- 使用expect和ssh远程执行命令的脚本
- shell脚本无密码登录 expect使用
- 无密钥登录的自动脚本实现(ssh-copy-id、expect免交互输入脚本)
- 使用expect脚本登录到root账号并执行命令
- Linux使用expect实现自动登录的脚本
- [置顶] Linux下用expect实现ssh自动登录并执行脚本
- 使用expect实现自动交互,自动登录脚本
- shell脚本精华----在10秒内SSH登录失败次数超过3次就使用iptables/tcpwrappers拒绝
- 使用linux expect进行ssh和telnet自动化登录等操作
- 使用expect工具ssh登录远程服务器并执行命令操作
- 使用expect实现自动登录的脚本
- shell脚本无密码登录 expect的使用方法详解