expect

Expect command output to be stored in a variable

Hi I have written below script . #! /usr/bin/expect set timeout 180 spawn /vobs/iov/rnc/bin/moshell/moshell -d db.dat expect { -re "OFFLINE_DB.DAT.*" { } timeout { error "\n######## Timeout - when logging in\n" } eof { error "\n######## eof - when logging in\n" } } set db_prompt "SQL...

How to return spawned process exit code in Expect script?

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 scri...

automating ssh login: tcl expect interact comand behaves weird

I wanted to automate ssh logins. After some research, it seemed like tcl/expect was the route to go. However, my issue is that when interact takes over my terminal, stuff doesn't work as expected (pun not intended). For example, if I resize the terminal, it does not "take". Also, sometimes the interact is not responsive, and sometimes...

How would I use ExpectJ to call pg_dump (on PostgreSQL 8.4) in Java?

Hello, I've seen this problem many places, that is to say the problem with programmatically making backups from PostgreSQL. My solution is to use ExpectJ, but I'm having trouble getting my code to work. I have the following code: public class BackupUtility { public static void main(String[] args) { try { ExpectJ exp = new E...

How do I accomplish if-else in Perl Expect?

Hi, I am using Expect in Perl to accomplish one task. After sending the command I am expecting either Success or ERROR as the output, depending on which I need to print to a file saying that it was successful or failed. $exp->expect(30, '-re', "Success", printf LOG "Successfully Deleted \n" => sub {exp_last;}, '-re', "ERROR", ...

Redirecting the output of expect to logfile in expect

Hi I am using expect in perl. I want to redirect all the output that appears on the stdout console to a log file so that i can debug it in future. Currently i am using $exp->log_stdout(0); Instead of redirecting to this can i do it to a log file? if so how to do it? ...

Expect (the language) "couldn't compile regular expression pattern: quantifier operand invalid" error

I'm having trouble with an Expect regular expression. I'm trying to match on this output: RUC.hg0 : 6 +6 ITPOK.hg0 : 6 +6 ITUC.hg0 : 6 +6 ITPKT.hg0 : 6 +6 IT127.h...

How do I wrap an REPL using .NET?

I'm trying to make a .NET wrapper for an REPL (specifically Scheme, but I haven't got to where it matters). I looked for some sort of expect-style library, but I couldn't find one, so I've been using a System.Diagnostics.Process. I don't think I'm succeeding at reading and writing correctly. Here's my code; it's in IronPython, but I h...

Expect scripting, source and return.

On page 35, in the book "Exploring Expect", it says "The return command can be used to make a source command return. Otherwise, source returns only after executing the last command in the file." I don't quite understand what it's getting at. I'd like to know what this means and how this is useful. Thank you. ...

What can Expect do that Pexpect can not do?

Hello I am considering to start using Pexpect. On Pexpects homepage I find this: Q: Why not just use Expect? A: I love it. It's great. I has bailed me out of some real jams, but I wanted something that would do 90% of what I need from Expect; be 10% of the size; and allow me to write my code in Python instead of TC...

Why this expect script gives an error when it's run by cron?

I can run this expect script just fine using root or my own user account, however when I run it with cron, I always get an error. The OS is Ubuntu 8.04. Error email is as follows, Date: Thu, 26 Aug 2010 11:50:01 -0400 From: root@supa (Cron Daemon) To: root@supa Subject: Cron <root@supa> /home/myusername/bin/uploadmyip myserver.com can...

sh/expect/sudo/screen all needed together in one command.

What I need to have happen: PHP needs to launch an server app which has root permissions running in the background. All of this should be silent. -Sudo is needed to allow php to perform an op that requires root permissions. -Screen is required to allow the app to run outside the scope of the webpage which started the process. -Expect ...

Is Expect Scripts Still Worth Learning?

Hi, Is still worth learning expect? Because I have not seen any new books on this topic? What would anyone recommend for a good book on this? ...

Input to Expect Script

in my test file, I had this line hello$LG. So, if I do `cat /test` It will show in my bash shell - hello$LG But when I try to do this in my expect script, $> expect test.sh `cat /test` It gives me this {hello$LG} . I don't know why it is getting {}. Anyone knows how to fix this? ...

How can I pass a filehandle to Perl Expect's log_file function?

I feel stupid for asking this, but I've tried a couple things and I'm not sure where to go with it. From the Expect.pm documentation: $object->log_file("filename" | $filehandle | \&coderef | undef) Log session to a file. All characters send to or received from the spawned process are written to the file. I'd like to pass t...

Problem with ssh application using expect

#!/usr/bin #read the input parameters set cmd1 [lindex $argv 0]; set cmd2 [lindex $argv 1]; set usr [lindex $argv 2]; set pwd [lindex $argv 3]; set ip [lindex $argv 4]; #sftp to specified host and send the files spawn ssh $ip expect { "Password:" { send "$pwd\r" expect { ...

could not able to spawn(ssh) using expect

Hi.. while executing $expect filename.exp user pwd ip I got the error could not execute "ssh -l user ip": no such file or directory The contents of filename.exp are this: #!/opt/sfw/bin/expect -D set OMC_Usr [lindex $argv 0] set OMC_Pwd [lindex $argv 1] set OMC_IP [lindex $argv 2] set cmd "ssh -l $OMC_Usr $OMC_IP" spawn $c...

Ruby version of the TCL-based Expect?

Expect seems to be a very powerful automation tool: http://www.nist.gov/mel/msid/expect.cfm Is there a Ruby equivalent to that tool? ...

Other solutions/languages that are superior to the TCL-based Expect?

I am amazed by how Expect (TCL) can automate a lot of things I normally could not do. I thought I could dig deeper into Expect by reading a book, but before I do that I want to ask if there are other solutions/languages that could do what Expect does? Eg. I have read that people compare Expect with Awk and also Perl. Could Awk and Per...

Expect works great interactively but not from file

It works great when I use expect interactively like this: root@vagrantup:/home/vagrant> expect -i expect1.1> spawn screen -x spawn screen -x 3195 expect1.2> send "ls\n" expect1.3> exit But the same commands used in a file: spawn screen -x send "ls\n" exit Only works sometimes, eg. 1/10 time every time I execute the file. It's reall...