expect实现脚本中ssh密码输入
来源:互联网 发布:宝山行知幼稚园 编辑:程序博客网 时间:2024/04/29 22:07
#!/usr/bin/expect
if { [llength $argv] < 4 } {
puts "Usage: $argv0 ip user passwd port commands timeout"
exit 1
}
match_max 600000
set ip [lindex $argv 0]
set user [lindex $argv 1]
set passwd [lindex $argv 2]
set port [lindex $argv 3]
set commands [lindex $argv 4]
set timeoutflag [lindex $argv 5]
set yesnoflag 0
set timeout $timeoutflag
for {} {1} {} {
# for is only used to retry when "Interrupted system call" occured
spawn /usr/bin/ssh -q -l$user -p$port $ip
expect {
"assword:" {
send "$passwd\r"
break;
}
"yes/no)?" {
set yesnoflag 1
send "yes\r"
break;
}
"FATAL" {
puts "\nCONNECTERROR: $ip occur FATAL ERROR!!!\n"
exit 1
}
timeout {
puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
exit 1
}
"No route to host" {
puts "\nCONNECTERROR: $ip No route to host!!!\n"
exit 1
}
"Connection Refused" {
puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
exit 1
}
"Connection refused" {
puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
exit 1
}
"Host key verification failed" {
puts "\nCONNECTERROR: $ip Host key verification failed!!!\n"
exit 1
}
"Illegal host key" {
puts "\nCONNECTERROR: $ip Illegal host key!!!\n"
exit 1
}
"Connection Timed Out" {
puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
exit 1
}
"Interrupted system call" {
puts "\n$ip Interrupted system call!!!\n"
}
}
}
if { $yesnoflag == 1 } {
expect {
"assword:" {
send "$passwd\r"
}
"yes/no)?" {
set yesnoflag 2
send "yes\r"
}
}
}
if { $yesnoflag == 2 } {
expect {
"assword:" {
send "$passwd\r"
}
}
}
expect {
"#" {send "$commands \r"}
">" {send "$commands \r"}
"$" {send "$commands \r"}
"assword:" {
send "$passwd\r"
puts "\nPASSWORDERROR: $ip Password error!!!\n"
exit 1
}
}
expect {
"#" {send "sleep 1 \r"}
">" {send "sleep 1 \r"}
"$" {send "sleep 1 \r"}
}
expect {
"#" {send "exit\r"}
">" {send "exit\r"}
"$" {send "exit\r"}
}
expect eof {
puts "OK_SSH: $ip\n"
exit 0;
}
[root@mydb1 home]# cat ndbstop.sh
#!/bin/bash
#mysql节点
mgmip1=192.168.1.91
mgmip2=192.168.1.94
ndbip1=192.168.1.91
ndbip2=192.168.1.94
mysqlip1=192.168.1.91
mysqlip2=192.168.1.94
#管理节点启动
#mgmstart="ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial"
sqlstop="service mysql stop"
mgmstop='ndb_mgm -e shutdown'
echo $mgmstop
/home/test.exp $mgmip1 root root001 22 "${mgmstop}" 10
/home/test.exp $mgmip2 root root001 22 "${mgmstop}" 10
#/home/test.exp $mgmip1 root root001 22 $ndbmtd 20
#/home/test.exp $mgmip2 root root001 22 $ndbmtd 20
/home/test.exp $mgmip1 root root001 22 "${sqlstop}" 20
/home/test.exp $mgmip2 root root001 22 "${sqlstop}" 20
- expect实现脚本中ssh密码输入
- 使用expect脚本实现Linux中自动输入密码
- expect实现scp ssh自动输入密码登录
- Shell脚本中调用expect,实现自动输入密码的功能
- expect实现自动输入密码
- 使用expect自动输入ssh密码
- 脚本ssh连接自动填密码(expect)
- 无密钥登录的自动脚本实现(ssh-copy-id、expect免交互输入脚本)
- linux、mac上用expect脚本实现脚本自动输入密码
- linux、mac上用expect脚本实现脚本自动输入密码
- expect实现自动化模拟输入scp/ssh
- expect脚本实现批量ssh互信
- 用expect实现的ssh脚本
- Expect ssh免秘钥登入自动脚本(ssh-copy-id、expect免交互输入脚本)
- 通过expect实现scp密码自动输入
- 用expect实现自动化输入密码
- 在shell脚本中用expect 实现 scp 文件的时候不手动输入密码
- 在shell脚本中用expect 实现 scp 文件的时候不手动输入密码
- 截取两个字符串中间字符
- qml TypeError: Cannot read property 'xxx' of undefined 错误处理
- 【风宇冲】Unity3D教程宝典之Shader篇:目录
- HTML5主体结构元素
- Get Post请求方式的乱码问题处理
- expect实现脚本中ssh密码输入
- Android基础知识--Preference的使用
- 写博客计划
- stl string常用函数
- 关于绝对定位一些讨论
- mysql group by 查询语句
- 项目管理与platform
- Android6.0权限管理依赖库的介绍和使用
- js 继承拷贝