expect

Expect免交互

半世苍凉 提交于 2019-12-30 23:44:45
一、expect 概述: (1)expect 是建立在 tcl 基础上的一个工具,expect是用来进行自动化控制和测试的工具,主要解决shell脚本中不可交互的问题。对于大规模的linux运维很有帮助 (2)在linux 运维和开发中,我们经常需要远程登录服务器进行操作,登录的过程是一个交互的过程,可能会需要输入yes/no password等信息。为了模拟这种输入,可以使用expect脚本。 (3)安装 yum install expect -y 二、基本命令: (1)send:向进程发送字符串,用于模拟用户的输入(该命令不能自动回车换行,一般要加 \r (回车)) (2)expect :判断上次输出结果里是否包含指定的字符串,如果有则立即返回,否则就等待超时时间后返回,只能捕捉由 spawn 启动的进程的输出。 (3)sapwn :启动进程,并跟踪后续交互信息 。 (4)interact :执行完成后保持交互状态,把控制权交给控制台。 (5)timeout : 指定超时时间,过期则继续执行后续指令。 单位为:秒 timeout -1 为永不超时 默认情况下,是10秒 (6)exp_continue :允许expect 继续向下执行指令 (7)send _user :相当于echo (8)$argv 参数数组: expect脚本可以接受从bash传递的参数,可以使用

Unattended (no-prompt) Homebrew installation using expect

只谈情不闲聊 提交于 2019-12-30 18:24:09
问题 According to the Homebrew installation instructions, the following command can be used to install: ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)" This works, but it needs user input two times; to confirm the install and in a sudo prompt invoked by the script: $ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)" ==> This script will install: /usr/local/bin/brew /usr/local/Library/... /usr/local/share/man/man1/brew.1 Press RETURN to continue

How to automate console scenario using TCL script? [closed]

浪尽此生 提交于 2019-12-30 11:32:12
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I want to automate the following scenario: Login into a router Give reload When reloading a router, press ESP key continuously. When pressing a ESP key , boot> prompt will come. execute some commands in this. I can do the above things manually, using "Teraterm" and console. But

How to automate console scenario using TCL script? [closed]

邮差的信 提交于 2019-12-30 11:32:07
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I want to automate the following scenario: Login into a router Give reload When reloading a router, press ESP key continuously. When pressing a ESP key , boot> prompt will come. execute some commands in this. I can do the above things manually, using "Teraterm" and console. But

How to return spawned process exit code in Expect script?

荒凉一梦 提交于 2019-12-29 05:46:48
问题 I use expect for running test scripts. Tests return success/failure through exit code. But expect return equivalent exit code. How to make expect return proper exit status? My tests are sql scripts run with psql (postgresql command processor). Since psql doesn't allow to specify database password as a command line parameter, expect scripts do that. So, my expect script looks like: spawn $SPAWN_CMD expect { -re "Enter password for new role:" { send "$PWPROMPT\n" exp_continue } -re "Enter it

Is there an Expect equivalent gem for Ruby?

陌路散爱 提交于 2019-12-28 05:44:47
问题 Is there an Expect equivalent gem for Ruby? I tried searching on code.google and rubygems.org, but sadly it did not show up. FYI: 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. 回答1: Ruby comes with the PTY module for setting up pseudoterminals to drive interactive command line applications. With it comes an expect method that allows

Using conditional statements inside 'expect'

孤街浪徒 提交于 2019-12-28 05:16:26
问题 I need to automate logging into a TELNET session using expect , but I need to take care of multiple passwords for the same username. Here's the flow I need to create: Open TELNET session to an IP Send user-name Send password Wrong password? Send the same user-name again, then a different password Should have successfully logged-in at this point... For what it's worth, here's what I've got so far: #!/usr/bin/expect spawn telnet 192.168.40.100 expect "login:" send "spongebob\r" expect "password

Using conditional statements inside 'expect'

大兔子大兔子 提交于 2019-12-28 05:16:06
问题 I need to automate logging into a TELNET session using expect , but I need to take care of multiple passwords for the same username. Here's the flow I need to create: Open TELNET session to an IP Send user-name Send password Wrong password? Send the same user-name again, then a different password Should have successfully logged-in at this point... For what it's worth, here's what I've got so far: #!/usr/bin/expect spawn telnet 192.168.40.100 expect "login:" send "spongebob\r" expect "password

Using expect to pass a password to ssh

白昼怎懂夜的黑 提交于 2019-12-27 11:41:14
问题 How can I use expect to send a password to an ssh connection. say the password was p@ssword and the ssh command was ssh me@127.0.0.1 What would I do with expect to a make it input the password when it says me@127.0.0.1's password: ? The proper action of using an SSH key pair isn't an option because I would have to use ssh (scp) to put the key on the server, which would ask for a password. 回答1: I always used the "proper" solution, but I used expect in other situations. Here I found following

Running multiple instances of one tcl script

荒凉一梦 提交于 2019-12-26 03:33:36
问题 Currently I am reading in host names from a file using a foreach command and using this hostname to connect to the device. All this is done within my TCL script. Is there a way I can run multiple instances of the script so that each device is queried separately? Something like a bash script similar to: for hostname in file; do log.tcl $hostname & done I believe this is similar to multi threading. Another question I have is that, when running multiple instances of a script, and each script