手机
当前位置:查字典教程网 >脚本专栏 >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脚本】相关文章:

linux下自动备份MySQL数据并上传到FTP上的shell脚本

linux下实现ftp自动备份shell脚本

putty实现自动登录的方法(ssh和ssh2)

自己常用的一些shell脚本分享

获取服务器信息的Shell脚本分享(ubuntu、centos测试通过)

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

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

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

统计 cpu 内存 使用率的shell脚本代码

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

精品推荐
分类导航