首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >期望在登录提示下发送$expect_out(缓冲区)

期望在登录提示下发送$expect_out(缓冲区)
EN

Stack Overflow用户
提问于 2013-06-25 06:18:16
回答 1查看 796关注 0票数 0

Expect是在提示输入用户凭据时发送$expect_out(缓冲区),而不是指定变量($user)。然后就超时了。以下是代码:

代码语言:javascript
复制
...
    }
    "yes" {
        send_user "\nEnter your username for the WLC supporting the new APs:\n"
        sleep 6
    }
}
expect {
    -re "(.*)\n" {
        set user $expect_out(1,string)
    }
}
send_user "\nEnter your password for the WLC supporting the new APs:\n"
sleep 15
expect {
    -re "(.*)\n" {
        set pass $expect_out(1,string)
    }
}
sleep 1
send_user "\nSshing to the IP of the WLC supporting the new APs ($wlc_temp)\n"
spawn ssh $wlc_temp

expect {
    "User:" {
        send $user\n
        sleep 1
    }
}
expect {
    "assword:" {
        send $pass\n
        sleep 1
    }
}

结果如下:

用户:(设备主机名)用户:

以下是首次亮相:

支持新的APs ()派生ssh父级的WLC的IP :等待同步字节父级:告诉子进程前进,父级:现在与子生成不同步:返回{7153} expect:"“(spawn_id exp6)是否与”用户:“匹配?不是 expect:"\r\n“(spawn_id exp6)与glob模式"User:”匹配吗?否(设备主机名)用户: expect:“\r\n(设备主机名) User:”(spawn_id exp6)与glob模式"User:“匹配吗?是的: set expect_out(0,string) "User:“expect: set expect_out(spawn_id) " exp6”expect: set expect_out(缓冲区)“\r\n(设备主机名)用户:”发送:发送"\n“到{exp6} 预期:“”(spawn_id exp6)匹配单词"assword:“吗?不是 (设备主机名)用户: expect:“\r\n(设备主机名)用户:”(spawn_id exp6)与glob模式"assword:“匹配吗?没有期望:超时

更新:将请求用户输入的语句重新定位到脚本的顶部,作为一项工作。

EN

回答 1

Stack Overflow用户

发布于 2013-06-25 08:12:10

当您想从用户读取输入时,应该使用expect_user而不是expect

代码语言:javascript
复制
        send_user "\nEnter your username for the WLC supporting the new APs:\n"
        sleep 6
    }
}
expect_user {
    -re "(.*)\n" {
        set user $expect_out(1,string)
    }
}
send_user "\nEnter your password for the WLC supporting the new APs:\n"
sleep 15
expect_user {
    -re "(.*)\n" {
        set pass $expect_out(1,string)
    }
}
sleep 1
send_user "\nSshing to the IP of the WLC supporting the new APs ($wlc_temp)\n"

# ...

(我还认为可以在其中使用更少的sleep调用,而只是调整超时,但这不太可能对脚本的正确操作产生影响。)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17290385

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档