zoukankan      html  css  js  c++  java
  • expect介绍

    首先介绍下shell中的expect:

    expect是处理交互的命令,可以将交互 过程如:ssh登录,ftp登录等写在一个脚本上,使之自动化完成.尤其适用于需 要对多台服务器执行相同操作的环境中,可以大大提高系统管理人员的工作效率 

    expect [选项] [ -c cmds ] [ [ -[f|b] ] cmdfile ] [ args ] 

        选项 

              -c:从命令行执行expect脚本,默认expect是交互地执行的   

                    示例:expect -c 'expect " " {send "pressed enter "} 

             -d:可以输出输出调试信息   

                   示例:expect  -d ssh.exp

              expect中相关命令 

                    spawn:启动新的进程 

                    send:用于向进程发送字符串 

                    expect:从进程接收字符串 

                    interact:允许用户交互

                   exp_continue  匹配多个字符串在执行动作后加此命令 

     expect最常用的语法(tcl语言:模式-动作) 

            单一分支模式语法: 

                  expect “hi” {send “you said hi "}           匹配到hi后,会输出“you said hi”,并换行

            多分支模式语法: 

                  expect "hi" { send "you said hi " } "hehe" { send “hehe yourself " } "bye" { send “good bye " } 

            匹配hi,hello,bye任意字符串时,执行相应输出.等同如下:

                 expect { "hi" { send "you said hi "} "hehe" { send "hehe yourself "} "bye" { send “good bye "} } 

  • 相关阅读:
    Algs4-2.2.1给出原地归并排序merge的排序过程
    Algs4-2.2.2给出自顶向下归并排序的排序过程
    Algs4-2.1.38不同类型的元素
    Algs4-2.1.36不均匀的数据
    Algs4-2.1.37部分有序
    Algs4-2.1.35不均匀的概率分布
    Algs4-2.1.34罕见情况
    升级python到2.7版本pip不可用
    随机验证码
    python文件操作
  • 原文地址:https://www.cnblogs.com/wyglog/p/12432820.html
Copyright © 2011-2022 走看看