expect

How to pass argument in expect through command line in shell script

独自空忆成欢 提交于 2019-12-03 04:41:18
问题 I am passing argument in expect through command line in shell script I tried this #!/usr/bin/expect -f set arg1 [lindex $argv 0] spawn lockdis -p expect "password:" {send "$arg1\r"} expect "password:" {send "$arg1\r"} expect "$ " but it's not working. Please help me to figure it out. Thanks 回答1: If you want to read from arguments, you can achieve this simply by set username [lindex $argv 0]; set password [lindex $argv 1]; And print it send_user "$username $password" That script will print $ .

Expect - Interrupt program - Ctrl+C

北战南征 提交于 2019-12-03 04:32:10
I am running the following script to start a capture on a remote server and download the file afterwards. Currently I have to pause it with Ctrl + C and manually exit. How can I replace the interact and define a trigger to kill the tcpdump or catch the Ctrl + C and pass it inside the remote server? spawn ssh "$user_ssh\@$ssh_server" expect { "*password" { send "$pass\n"; exp_continue} "root\@*" { } timeout { puts "time out expecting password or bash"; exit 1 } } send "sudo tcpdump -i $intf -s0 -w $file -v\n"; interact spawn scp "$user_ssh\@$ssh_server:$file" . expect "password:" send "$pass

How to access environment variables in an Expect script?

时间秒杀一切 提交于 2019-12-03 04:16:10
I would like to access the PATH environment variable inside an expect script. How can I achieve that ? My actual script is : #!/usr/bin/expect set timeout 300 send "echo $PATH\r" and its ouput is : can't read "PATH": no such variable while executing "send "echo $PATH\r"" Expect is an extension of Tcl . Tcl access enviroment variables via the global env array : send_user "$env(PATH)\n" You can use the global env array by using: $::env(PATH) This notion will also work inside procedures. If you want to read the target $PATH variable, then you must escape the "$" : exp_sent -- echo "\$PATH\r" 来源:

React - how to test form submit?

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following React component: export default class SignUpForm extends React.Component { ... doSignupForm(event) { // Some API call... } render() { return ( <div> <form action="/" onSubmit={this.doSignupForm.bind(this)} id="register-form"> <button type="submit" id="register_button">Sign Up</button> </form> </div> ); } }; I want to test that the button fires the doSignupForm function - how do I do this (ideally using Mocha/Chai/Enzyme/Sinon)? In addition, as you can see the doSignupForm function fires an API call - should this API call

Apache and mod_proxy not handling HTTP 100-continue from client HTTP 417

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: 'm building some webby magic and am using Apache to front our tomcat server, forwarding requests to tomcat on port 8080. I have an issue using Apache and mod_proxy to forward requests. It appears the client (a web application) sends an HTTP 100-continue to which Apache responds with a 417 Expectation Failed. When I take Apache out of the picture and send requests directly to tomcat on port 8080, the request is successful and the client is sent a 200 OK. My Apache config looks like: ServerName abcproxy DocumentRoot /apps/apache

Spring MockRestServiceServer handling multiple requests to the same URI (auto-discovery)

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Let's say I am writing Spring integration tests for a REST service A. This service in turn hits another REST service B and gets a list of URIs to hit on REST service C. It is kind of auto-discovery pattern. I want to mock B and C responses using MockRestServiceServer. Now the response from B is a list of URIs, they are all very similar, and for the sake of the example lets say my response from B is like so: { uris: ["/stuff/1.json", "/stuff/2.json", "/stuff/39.json", "/stuff/47.json"] } Simply service A will append each of them onto base URL

Chai: expecting an error or not depending on a parameter [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: Mocha / Chai expect.to.throw not catching thrown errors 5 answers I've been trying to do a text of a function that handles errors in a way that, if it is a valid error, it is thrown, but if it is not, then nothing is thrown. The problem is that i cant seem to set the parameter while using: expect(handleError).to.throw(Error); The ideal would be to use: expect(handleError(validError)).to.throw(Error); Is there any way to achieve this functionality? code of the function: function handleError (err) { if

Ruby - Problems with Expect and Pty

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to write a Ruby script that will ssh over to a server, run a given command, and fetch the output from it. Here's what I've got so far, mostly adapted from the Programming Ruby book: require 'pty' require 'expect' $expect_verbose = true PTY.spawn("ssh root@x.y") do |reader, writer, pid| reader.expect(/root@x.y's password:.*/) writer.puts("password") reader.expect(/.*/) writer.puts("ls -l") reader.expect(/.*/) answer = reader.gets puts "Answer = #{answer}" end Unfortunately all I'm getting back is this: Answer = .y's password: Any

Print message on expect() assert failure

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way to print a custom error message when a Jasmine expect() fails? As an example, for end to end testing I have an array of web pages and I use one test to go to each URL and assert an element exists on each page. I know I can put every expect() into a separate test, but I'd rather iterate through the array and log the page URL on failure. 回答1: UPDATE I see people still are finding this. Later information from the Jasmine team is that there is an undocumented feature on the expect - you can include a custom failure message and it

Handle multiple Spawn process in expect script

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Here is my use case for expect script ( one of few i have) I want to run multiple sed command over ssh. Its like pre-build environment setup. I want to run something like this :- #!/usr/bin/expect set timeout -1 spawn -noecho bash -c "ssh -t user@host 'sed -i <some_stuff1> <file1>'" spawn -noecho bash -c "ssh -t user@host 'sed -i <some_stuff2> <file2>'" spawn -noecho bash -c "ssh -t user@host 'sed -i <some_stuff3> <file3>'" expect { -re ".*sword.*" { exp_send "$env(PASS_WORD)\n" exp_continue } } But only last sed command will execute. 1st