expect

Expect Escaping with Awk

别说谁变了你拦得住时间么 提交于 2020-01-06 19:51:07
问题 I need to process the output of a single record psql query through awk before assigning it to a value in my expect script. The relevant code: spawn $env(SHELL) send "psql -U safeuser -h db test -c \"SELECT foo((SELECT id FROM table where ((table.col1 = \'$user\' AND table.col2 IS NULL) OR table.col2 = \'$user\') AND is_active LIMIT 1));\" | /bin/awk {{NR=3}} {{ print $1 }}; \r" expect "assword for user safeuser:" send "$safeuserpw\r" expect -re '*' set userpass $expect_out(0, string) When I

Call expect file from C

旧街凉风 提交于 2020-01-06 19:14:09
问题 I coded a ftp.exp file which sends a log file of a C application to a server. #!/usr/bin/expect set timeout -1 spawn ftp xxx.xxx.xxx 21 match_max 100000 expect -re {[2]{2,}[0]{1,}} send -- "usrxxxx" expect -exact "usrxxxxx" send -- "\r" expect -re {[3]{2,}[1]{1,}} send -- "xxxx\r" expect -exact "\r 230 Access granted for xxxxxxxxxx !\r Remote system type is UNIX.\r Using binary mode to transfer files.\r ftp> " send -- "put /home/User/test.txt test2.txt\r" expect -exact "put /home/User/test

I want to open terminal sessions that are pre populated with commands on the command line

百般思念 提交于 2020-01-06 18:08:36
问题 When I log onto my assorted PCs I usually have a number of things I want to happen automatically, but not always straight away. These include starting terminal sessions in specific locations on specific desktops (because you get used to using the same layout) and those terminal sessions performing specific acts such as ssh commands. However sometimes when you logon after a reboot you may not want to execute those commands immediately as a higher priority action may need your attention first.

How to get the Java stream for ExpectIt to drive Telnet

不想你离开。 提交于 2020-01-06 16:53:25
问题 How do I get the Java stream for telnet to use with the ExpectIt? Instead of using a Java library, such as Apache Telnet as below, using the actual Telnet client on Linux. This is in the context of the man page from expect: Expect is a program that "talks" to other interactive programs according to a script. followup question with a much more narrow scope to a previous, vague, overly broad question where the following comment was made: The library, as all the other Java libraries, uses

Expect Script to Send Different String Outputs

只愿长相守 提交于 2020-01-06 14:51:09
问题 I have something like this. expect "hi" { send "You said hi\n" } "hello" { send "Hello yourself\n" } "hi" { send "2nd time you said hi\n" } The scenario is I will get a initial response 'hi', then 'hello', then 'hi' again. The second time I get a response of 'hi', I want to send a different string. Thanks. 回答1: You should use a list and iterate... set responses {{You said hi} {2nd time you said hi}} set idx 0 while {$idx < [llength $responses]} { expect { "hi" { send [lindex $responses $idx]

expect script capturing garbage characters - need to remove

浪子不回头ぞ 提交于 2020-01-06 08:05:10
问题 I have a switch I'm trying to write to grab output from a hp switch. The source machine is an ubuntu 18.04. The code version on the switch is 16.04. I tried changing the terminal settings on the switch from the default of vty100 to ansi and none but no difference. How do I get rid of the extra special characters show below? set timeout 20 spawn ssh -l manager 192.168.10.10 expect "manager@192.168.10.10's password:" send "admin\n" expect "Press any key to continue" send "j\n" log_file -a hp

expect script: string with square braces doesn't match

ε祈祈猫儿з 提交于 2020-01-05 08:47:33
问题 I'm absolutely new to expect command. Suppose that there is a script file named 'a.rb', which is written in ruby: STDOUT << 'Overwrite /opt/rails/rails_app/Gemfile? (enter "h" for help) [Ynaqdh] ' s = STDIN.gets STDOUT << s It works as bellow: $ruby a.rb Overwrite /opt/rails/rails_app/Gemfile? (enter "h" for help) [Ynaqdh] #wait user's input y # show the user's input and exit It seems good to use expect command if I want to automate the user's input. So I tried to make a script file (a.expect

Writing tests that use GDB - how to capture output?

帅比萌擦擦* 提交于 2020-01-05 07:21:06
问题 I am trying to write tests that interact with GDB but am having trouble capturing the output. I would like for a log file to be generated which looks like what would have been seen in a terminal had the test been executed by hand. GDB is proving to be very stubborn when it comes to capturing its output however. I've been able to write Expect scripts which are able to interact with GDB and whose output can be redirected to a log file but I don't want to write my tests in TCL. I'm hoping to use

Writing tests that use GDB - how to capture output?

两盒软妹~` 提交于 2020-01-05 07:21:04
问题 I am trying to write tests that interact with GDB but am having trouble capturing the output. I would like for a log file to be generated which looks like what would have been seen in a terminal had the test been executed by hand. GDB is proving to be very stubborn when it comes to capturing its output however. I've been able to write Expect scripts which are able to interact with GDB and whose output can be redirected to a log file but I don't want to write my tests in TCL. I'm hoping to use

Expect within bash script

时光总嘲笑我的痴心妄想 提交于 2020-01-04 08:20:47
问题 I am trying to implement an expect script into a bash script. Bear with me since I am fairly new to bash/expect. Here is the expect script that works as intended: log_user 0 file delete foo.txt set fh [open foo.txt a] set servers {xxx@server1 xxx@server2} foreach s $servers { spawn ssh $s expect "password: " send "PASSWORD\r" expect "$ " send "grep "something" /some/log/file.log" expect "$ " { puts $fh "$expect_out(buffer)"} send "exit\r" } close $fh Now, I am hoping to include this expect