Re: How to catch erro from spawned command?
- From: Bruce Hartweg <doNOTuse@xxxxxxxxxxx>
- Date: Mon, 14 Apr 2008 17:49:24 -0500
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 aThe results (including errors) will come back to your expect script directly.
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.
No need to redirect to a file - you can use expect commands to deal with them.
Bruce- Hide quoted text -
- Show quoted text -
- Follow-Ups:
- Re: How to catch erro from spawned command?
- From: eric5931
- Re: How to catch erro from spawned command?
- References:
- Re: How to catch erro from spawned command?
- From: eric5931
- Re: How to catch erro from spawned command?
- From: Bruce Hartweg
- Re: How to catch erro from spawned command?
- From: eric5931
- Re: How to catch erro from spawned command?
- Prev by Date: Re: How to catch erro from spawned command?
- Next by Date: Re: How to catch erro from spawned command?
- Previous by thread: Re: How to catch erro from spawned command?
- Next by thread: Re: How to catch erro from spawned command?
- Index(es):
Relevant Pages
|
|