1 Reply Latest reply on Jun 17, 2008 8:26 AM by 807557

    Error handling in script

    807557
      Hi,

      I want to handle the error in a shell script..

      requirement is in a.sh i invoke b.sh.Within b.sh i do some ftp operations.Now i want to handle if any error occurs while doing ftp.I want to do do some commands if the ftp fails i.e.error occurs in b.sh....

      Thanx in advance
        • 1. Re: Error handling in script
          807557
          Should be simple enough ...
          a.sh:
          .
          .
          .
          b.sh
          rc=$?
          if [ $rc -ne 0 ]
          then
            echo "errors happend"
          fi
          .
          .
          b.sh
          .
          .
          .
          # Let's assume it will fail ...
          RESULT=1
          # Do some ftp stuff and determine if it worked
          # that needs to be up to you how to decide that
          # if it HAS worked then:
          if [ $it_worked -eq 0 ]
          then
            RESULT=0
          fi
          
          exit $RESULT
          The $it_worked variable (and the if test) is just there to show the RESULT=0 - ypu'll need to work out how to decide if the ftp stuff worked