手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >用expect实现的自动登录到多台服务器的shell脚本
用expect实现的自动登录到多台服务器的shell脚本
摘要:复制代码代码如下:#!/usr/bin/expect-fsetipaddress[lindex$argv0]setpasswd[lindex...

复制代码 代码如下:

#!/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 "yesr"

expect "password:"

send "$passwdr"

expect "]*"

send "mkdir -p /tmp/haha/haha2r"

send "exitr"

***************

expect {

"(yes/no)?" {

send "yesn"

}

"password:" {

....

}

判断语句

if {$havepass == 0} {

expect "password:" { send "$pwn" }

}

或者:

expect {

"yes/no" { send "yesr"; exp_continue}

"password:" { send "$passwdr" }

}

【用expect实现的自动登录到多台服务器的shell脚本】相关文章:

实现android自动化测试部署与运行Shell脚本分享

Formatting Long Lines 格式化多行字符的shell脚本

实时查看系统流量的Shell脚本分享

用来记录登录后使用命令的shell脚本

两个备份数据库的shell脚本

Linux oracle数据库自动备份自动压缩脚本代码

控制输出颜色的shell脚本

expect自动检测并重启另外一台服务器上的程序代码

linux下监视进程 崩溃挂掉后自动重启的shell脚本

脚本实现SSH登录邮件报警

精品推荐
分类导航