Re: How to catch erro from spawned command?



eric5931@xxxxxxxxx wrote:
hi Bruce,

I just tested. The expect script will not catch the "No route to
host". It will only catch the "eof" afterward which left me no clue
about the "eof" is from a successful action or failed one.


yes it does - the eof pattern is what you want.
inside there you can look at the contents of expect_out(buffer) to see
the messages, and also the results of a call to wait will give you
the exit status of your spawned program.

Eric.


On Apr 14, 2:10 pm, Bruce Hartweg <doNOT...@xxxxxxxxxxx> wrote:
eric5...@xxxxxxxxx wrote:
Sorry I hit the wrong key and the message just got sent. Here is a
rewrite:
I have a problem with this in expect:
spawn ssh f...@xxxxxxxxxxxxxxx ls -l > /tmp/mylog 2>&1
while (1) {
expect timeout { puts "get timeout\n"; exit 99} \
"Are you sure*" { send "no\r"; break; } \
"*password: $" { send "$passwd\r"; continue; } \
eof { puts "get eof\n"; break;} \
default { puts "get default\n"; break;};
}
The problem is if "ssh" failed, like the script get a dummy ip
address, the erro message, "ssh: connect to host 123.123.123.123 port
22: No route to host" didn't get to /tmp/mylog. This is because
expect think my command is
'spawn ssh f...@xxxxxxxxxxxxxxx "ls -l > /tmp/mylog 2>&1" '
but what I really want is
'spawn "ssh f...@xxxxxxxxxxxxxxx ls -l" > /tmp/mylog 2>&1 '
so I can catch the ssh error.
How should I correct tghe command syntax?
Eric.
The results (including errors) will come back to your expect script directly.
No need to redirect to a file - you can use expect commands to deal with them.

Bruce- Hide quoted text -

- Show quoted text -

.



Relevant Pages

  • Re: How to catch erro from spawned command?
    ... You've got several problems with this expect script see comments ... if you want the ssh command to write to a file on the remote system ... # but we always want to wait for eof ... set buffer $expect_out; ...
    (comp.lang.tcl)
  • Getting "date" command to output the date in milli-seconds - Possible or not?
    ... Can anyone tell me if it is possible to get the AIX "date" command to output ... I need this to log the start time of a regularly called script. ... milli-seconds for logging purposes, and to aid in finding out why the remote ... host experiences a double call sometimes. ...
    (comp.unix.aix)
  • RE: script or other suggestion
    ... The command 'host' will look up an ip address and return the associated ... Subject: script or other suggestion ...
    (RedHat)
  • Re: How to catch erro from spawned command?
    ... It will only catch the "eof" afterward which left me no clue ... connect to host 123.123.123.123 port ... so I can catch the ssh error. ... The results will come back to your expect script directly. ...
    (comp.lang.tcl)
  • Re: How to get ssh to work in a loop
    ... > script for the sun systems which was quite easy as you only need to ... Drop cat (useless use of this command). ... I believe other UNIX systems) is to continually ping if 'ping HOST' is ... Running multiple ssh calls to the same system in a loop ...
    (comp.unix.shell)