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

Putty实现自动登陆远程Linux主机的方法

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

sed删除文件中的一行内容的脚本代码

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

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

nginx日志切割shell脚本

如何使用微博自动记录俯卧撑个数

linux使用select实现精确定时器详解

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

一个监控网卡流量的shell脚本

精品推荐
分类导航