expect script and error handling 
Author Message
 expect script and error handling

Hi, I am new to expect and tcl/tk. After I discovered expect a couple
weeks ago, I found it really interesting. I was able to start some
automation pretty soon. However, I am not sure hwo to do the following.
Basically I'd like to automatically telnet into a machine and run a few
ksh scripts or perl scripts on the remote machine (the remote machine
does not have tcl/tk or expect). The login part is done and I was able
to run the shell scripts in sunny day scenarios. My question is how do I
catch and deal with problems from execution of the shell scripts in my
expect scripts?
E.g.

# login stuff
..
# now, I have login
expect "myprompt>" { send "myscript1.sh\r" }
expect "myprompt>" { send "myscript2.sh\r" }
expect "myprompt>" { send "myscript3.sh\r" }
expect "myprompt>" { send "myscript4.sh\r" }

# done, so exit

Each of the shell scripts take a while ( 5-30minutes ) to execute. The
shell scripts will output error message by "echo or print". The shell
scripts will also "exit" with some numerical codes. If I can catch the
error messages and/or the exit codes, maybe I can deal this them in the
expect codes???

Any suggestion will be very helpful!

Shunde

--
Posted via http://www.*-*-*.com/



Sat, 14 May 2005 00:25:25 GMT  
 expect script and error handling

Quote:

>Hi, I am new to expect and tcl/tk. After I discovered expect a couple
>weeks ago, I found it really interesting. I was able to start some
>automation pretty soon. However, I am not sure hwo to do the following.
>Basically I'd like to automatically telnet into a machine and run a few
>ksh scripts or perl scripts on the remote machine (the remote machine
>does not have tcl/tk or expect). The login part is done and I was able
>to run the shell scripts in sunny day scenarios. My question is how do I
>catch and deal with problems from execution of the shell scripts in my
>expect scripts?
>E.g.

># login stuff
>..
># now, I have login
>expect "myprompt>" { send "myscript1.sh\r" }
>expect "myprompt>" { send "myscript2.sh\r" }
>expect "myprompt>" { send "myscript3.sh\r" }
>expect "myprompt>" { send "myscript4.sh\r" }

># done, so exit

>Each of the shell scripts take a while ( 5-30minutes ) to execute. The
>shell scripts will output error message by "echo or print". The shell
>scripts will also "exit" with some numerical codes. If I can catch the
>error messages and/or the exit codes, maybe I can deal this them in the
>expect codes???

>Any suggestion will be very helpful!

                        .
                        .
                        .
While you use idioms ("sunny day scenarios", for example)
unfamiliar to me, I believe I understand what you're after.

Expect has no direct access to the information you want.
telnet mediates all exchanges between Expect and the remote
host, and telnet simply does not preserve this information.

HOWEVER, there's no need to despair.  Arrange that the com-
mands you send through telnet make the desired data
accessible.  For the exit code, for example, do something
like
  expect $prompt
  send "perl some_program.pl\r"
  expect $prompt
  # I assume you're telnetting to something like ksh, bash, ...
  send "$?"
  expect $prompt
  expect -re (.*)\r\n$prompt"
  puts "See?  The exit code is '$expect_out(1,string)'."
--


Business:  http://www.Phaseit.net
Personal:  http://phaseit.net/claird/home.html



Sat, 14 May 2005 02:41:35 GMT  
 expect script and error handling
[...]

Quote:
> HOWEVER, there's no need to despair.  Arrange that the com-
> mands you send through telnet make the desired data
> accessible.  For the exit code, for example, do something
> like
>   expect $prompt
>   send "perl some_program.pl\r"
>   expect $prompt
>   # I assume you're telnetting to something like ksh, bash, ...
>   send "$?"
>   expect $prompt
>   expect -re (.*)\r\n$prompt"

I'm sure you meant:  
    send "echo \$?\r"
    expect -re "(.*)\r\n$prompt"

Quote:
>   puts "See?  The exit code is '$expect_out(1,string)'."

--
Glenn Jackman
NCF Sysadmin



Sat, 14 May 2005 03:05:13 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Starting Multiple Expect Scripts from a Single Expect Script

2. Expect scripts within expect scripts

3. Expect script calling Expect script

4. Advice on expect script to handle bad ftp connection

5. Expect Telnet Error Handle?

6. handling errors in expect

7. Calling an external prog - timeout and error-handling in Expect

8. expect: bgerror failed to handle background error.

9. Error handling - Expect under Windows

10. handling errors from spawn'ed commands in Expect

11. expect ftp error handling

12. Expect spawn error handling

 

 
Powered by phpBB® Forum Software