Error trap/detection question in sh

Error trap/detection question in sh

Post by Douglas Siebe » Thu, 04 Apr 1991 05:21:16



I have written a script in sh using named pipes to perform an unattended ftp
session.  I would like to insert some form of error checking/detection in it to
check for conditions such as "Network unreachable" and "Connection timed out"
etc.  I am using a command of the form:

ftp -n [address] < pipe > outfile &

where "pipe" is a named pipe created by "mknod pipe p"  I suppose I could add
something of the form 2>errorfile to trap errors and if the file is of positive
size assume something has occurred which I do not wish.  I am hoping for a
cleaner, better way though.  Any ideas?
--
________________________________________________________________________

MBA Student (2nd year)
The University of Iowa

 
 
 

Error trap/detection question in sh

Post by Jonathan I. Kame » Fri, 05 Apr 1991 06:13:17



|> where "pipe" is a named pipe created by "mknod pipe p"  I suppose I could add
|> something of the form 2>errorfile to trap errors and if the file is of positive
|> size assume something has occurred which I do not wish.  I am hoping for a
|> cleaner, better way though.  Any ideas?

  Get /pub/expect.shar.Z from ftp.uu.net, and write your script in expect
instead of trying to do it the way you are now; I suspect it'll be much
easier.  I believe you also need tcl to compile expect; tcl is available in
/pub/tcl.tar.Z on the same machine.

  If you want to find out what expect is all about, you can retrieve and print
out (after uncompressing it) the postscript file /pub/expect.ps.Z, which is
probably the paper that Don Libes presented about expect at a Usenix.

--
Jonathan Kamens                               USnail:
MIT Project Athena                              11 Ashford Terrace

Office: 617-253-8085                          Home: 617-782-0710

 
 
 

1. trap/sh -e question

Can anyone explain to me according to which rules
1. "echo $?" will be called and
2. what "echo $?" will output in the following script:

  #!/bin/sh -e
  trap 'echo $? ; exit' 0
  ...
  trap 0

I have difficulties to see the rules due to the following cases for "..." (script
is called "ttt"):

...             output                          exit status if called interactively
===================================================================================
[ ]             <none>                            1
-----------------------------------------------------------------------------------
( [ ] )         1                               1
-----------------------------------------------------------------------------------
unknown         ./ttt: unknown: not found       1
                0
-----------------------------------------------------------------------------------
( unknown )     ./ttt: unknown: not found       1
                1
-----------------------------------------------------------------------------------
( [ ] ) || :    <none>                            0
-----------------------------------------------------------------------------------
( [ ] ) && :    <none>                            1
-----------------------------------------------------------------------------------

2. 4.3-release and sawfish

3. Help with K-TRAP KERNAL TRAP error

4. Please help. What to do if a linux server should change the ip address ?

5. sh Xinstall.sh -check error

6. Redhat 5.2 ld problems

7. sh error message -> sh: 6919 memory fault

8. Upgraded motherboard and memory stopped working

9. strange traps in HP-UX /bin/sh

10. signal trapping problem in [k]sh...

11. ksh != sh on traps

12. trapping a kill -9 in sh

13. how to use trap in sh?