expect

while loop in expect script

落爺英雄遲暮 提交于 2019-12-14 00:41:39
问题 I'm new to expect scripting, I want to write something like this: set variable; $variable = expect -exact "\/----Enter Password----\\" while { != $variable } { send -- {^[-} } I want to keep sending escape+hyphen character until I expect this prompt: "/----Enter Password----\". I have written the above code but it is not working. How do I do this, kindly help me. 回答1: You can make use of exp_continue to handle this situation. The command exp_continue allows expect itself to continue executing

Send command while expect can get specific text

梦想的初衷 提交于 2019-12-13 20:03:35
问题 I Have one problem when i am using expect. I need to list some information. But the program list 10 items and then shows (More...) and waits a key So: expect "More..." send "\n" But the program shows more 10 lines and does it again, i can track how many times i need to do that, but the list changes a lot. Is there a way to do something like: while expect "More..." do send "\n" done I know the expect waits for a string, is there some kind of "hit" command? Thanks 回答1: You want exp_continue and

Expect script problems

寵の児 提交于 2019-12-13 18:55:14
问题 I am new to expect and i was using a logic to automate diconnecting telnet session where user is logged in and leave other lines as it is: for {set i 0} {$i ==4} {incr i} { send "clear line vty $i\r" "confirm]" {send "\r"} "% Not allowed" {send "quit\r"; exit} } it disconnects all the lines now i use "show user" command but it's hard for me to write a script around it, the output is not friendly enough for me.so i wrote IF statements in this for loop but it was not good and not even deserving

Is behavior of expect_after/expect_background in proc different than when called globally?

笑着哭i 提交于 2019-12-13 18:14:23
问题 I'm automating some work with expect, and have something like the following: # procedure to set background and after patterns proc foo {} { expect_after { -re $regex1 {puts "Matched regex1"; send $command_to_run; exp_continue} timeout {exp_continue} } expect_background { -re $regex2 {do other things; exp_continue} -re $regex3 {and more different things; exp_continue} timeout {exp_continue} } } spawn $thing foo expect_user { -ex "stahp" {exit} } This hangs indefinitely after expect_after

Get Total Memory of a host with LINUX/EXPECT

独自空忆成欢 提交于 2019-12-13 17:41:08
问题 I would like to get the total memory of a host by using a '.exp' script. After getting inside the host, I execute the following line: "send "top -n 1 | grep Mem: | awk '{ print $(NF-7) }' | cut -d 'k' -f1\r"" While executing the script, it returns the following error: can't read "(NF-7)": no such variable But if get manually inside the host, and execute the same line ( without the "send" part) , it returns me the expected number... What I'm doing wrong? Any idea? Any proposal for other way of

shell脚本免交互——ecpect

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

Expect Script Telnet email script

别来无恙 提交于 2019-12-13 10:34:03
问题 Trying to use Expect Script the Active TCL in Windows to send an email out every it is run. Below is the code I have but there is an error message displayed below and would appreciate any help on how to avoid the problem. Thank you. #!/usr/bin/expect # \ exec tclsh "$0" ${1+"$@"} package require Expect spawn plink -telnet IP PORT send "ehlo *******.com\r"; send "AUTH LOGIN\r"; expect "334 VXNlcm5hbWU6" sleep .1; send "*************\r"; sleep .1; expect "334 UGFzc3dvcmQ6\r" send "********\r";

Linux - Bash & Expect

我是研究僧i 提交于 2019-12-13 08:08:54
问题 I use expect to copy my key to remote linux boxes. copy_key #!/usr/bin/expect stty echo set REMOTEhost [lindex $argv 0] set REMOTEpass [lindex $argv 1] spawn ssh-copy-id -i /home/myuser/mykey.pub root@$REMOTEhost expect "password: " send "$REMOTEpass\n" sleep 2 This is called via ./copy_key 1.1.1.1 GENERATED_PASSWORD I'd like to migrate all of this to a bash script. Something like the following, which of course is something different but just to help with an idea: #!/bin/bash /usr/bin/expect

Using rsync in expect script with find -ctime give me an error?

拥有回忆 提交于 2019-12-13 05:28:19
问题 I need some help with an expect script and rsync. When I run rsync in command line like this it works fine: rsync -avz root@10.33.122.22:'$(find /cluster/storage/nobackup/coremw/var/log/saflog/FaultManagementLog/alarm/ -ctime -1)' /home/imstest/shared/Generate/ReportingT3/tmp/ But when I use my expect script that looks like this I get an error: #!/usr/bin/expect -f set host_ip [lindex $argv 0 ] set user [lindex $argv 1 ] set password [lindex $argv 2] set scp_remote_directory [lindex $argv 3 ]

Expect: invalid command name “*”

我是研究僧i 提交于 2019-12-13 03:46:39
问题 In my Expect script this line is throwing an error: expect "Address or name of remote host [*]? " In the log I see this error: switchnumber1#invalid command name "*" while executing "*" invoked from within "expect "Address or name of remote host [*]? "" The remote host ip address in the brackets could change. 回答1: Expect uses Tcl. In Tcl, [...] in double quotes is the command substitution syntax which is like $(...) (or `...` ) in Bash. To include a literal [ char you could write: expect