zoukankan      html  css  js  c++  java
  • expect script

    Expect script introduction(from wiki): 

     Expect is a Unix automation and testing tool, written by Don Libes as an extension to the Tcl scripting language, for interactive applications such as telnet, ftp, passwd, fsck,rlogin, tip, ssh, and others. It uses Unix pseudo terminals to wrap up subprocesses transparently, allowing the automation of arbitrary applications that are accessed over a terminal. With Tk, interactive applications can be wrapped in X11 GUIs.


    It is difficult to script the ssh and scp, passwd command into the shell script because of these cant get input from redirect file or something else,  while the expect is excellent to do it.

    The below expect shell to explain how to use expect script:

    #!/usr/bin/expect 

    set server   [lindex $argv 0]

    set account  [lindex $argv 1]

    set password [lindex $argv 2]

    set destination [lindex $argv 3]

    set build [lindex $argv 4]

    if { $server == "-h" ||  $server == "" } {

       spawn echo "paramter order : server : account : password : destinatioin : build"

       exit

    }

    spawn echo "server      : $server"

    spawn echo "account     : $account"

    spawn echo "password    : $password"

    spawn echo "destination : $destination"

    spawn echo "build       : $build"

    spawn echo "start to run the deployment======================================================>"

    spawn ssh $account@$server "mkdir -p worker/$destination; echo 'create dictinary'"

    expect {*password}

    send  "raas\r"

    spawn scp -r $build $account@$server:worker/$destination

    expect {*password:}

    send  "raas\r"

    expect eof

    spawn ssh $account@$server "echo 'run2'; cd worker/$destination; sh pyADPWorker.sh"

    expect {*password}

    send  "raas\r"

    expect eof 

  • 相关阅读:
    梯度下降_机器学习-李宏毅
    LeTex算法伪代码环境
    数据结构之线性表
    Java中的初始化块、构造器、静态初始化块的执行顺序
    Java中的内省(introspector)
    JSP (Java Server Page)
    eclipse的web工程默认部署到了哪里
    Persistence机制(永久保存/序列化Serialize)
    VC++中使用正则表达式RegExp
    Java中解析和生成xml
  • 原文地址:https://www.cnblogs.com/zhyg6516/p/1716455.html
Copyright © 2011-2022 走看看