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 

转载于:https://www.cnblogs.com/zhyg6516/archive/2010/04/20/1716455.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值