Rocket U2 | UniVerse & UniData

 View Only
  • 1.  Bash error on exit

    Posted 05-23-2022 16:32
    We are writing a deployment process for Azure and need to be able to set a Bash error if the deployment process generates an error. The script is executed from the shell level with "uv DEPLOYSCRIPT' and it will exit back to the shell when done. So far, after each test, I'm seeing a Bash exit code 0... How do I force an exit error, better yet with a message such as 'exit 1 FAILED TO COMPILE ABCD EFGH'...

    Jeff Teter
    Woodforest National Bank
    The Woodlands, TX

  • 2.  RE: Bash error on exit

    Posted 05-23-2022 21:28
    You could see if having your DEPLOYSCRIPT assign environment variables will allow them to be checked after the UV shell exits.

    ---within DEPLOYSCRIPT---
    ENV SET EXITMSG="Opps, something bad happened"

    ---you BASH logic---
    # unset our key environment variables before we start
    # to begin with a clean slate
    # deal with the results
    [ -n "${EXITMSG}" ] && echo "${EXITMSG}"
    exit ${EXITVAL}

    ​Failing that, you can easily write your result code and any appropriate message to a unix file before exiting uv, and use bash to read those and react.​​

    Gregor Scott
    Software Architect
    Pentana Solutions Pty Ltd
    Mount Waverley VIC AU

  • 3.  RE: Bash error on exit

    Posted 05-24-2022 20:09
    Hi Jeff,
    We do a similar thing but within AWS using their CodeDeploy stuff to deploy from BitBucket. I wrote several scripts to shift the source code out of BitBucket repository, tar it up and ship it to the destination UV host for installation. I the compile script I have the following lines to check the output of the compile.

    A central linux-based deployment server acts as the gateway between AWS CodeDeploy, BitBucket and our destination UniVerse server and runs the scripts.
    ## Excerpt from Peter's ""
    echo "`date '+%b %d %T'`       Unpacking source code to $BUILDHOST:$BUILDDIR" >> $LOGFILE
    #echo "ssh -l $BUILDUSER $BUILDHOST \"cd $BUILDDIR ; gunzip -c $SRCPKG | tar xf -\"" >> $LOGFILE
    ssh -l $BUILDUSER $BUILDHOST "cd $BUILDDIR ; gunzip -c $SRCPKG | tar xf -"
    echo "`date '+%b %d %T'`       Initiating the new build environment for $BUILDDIR" >> $LOGFILE
    ssh -l $BUILDUSER $BUILDHOST "cd $BUILDDIR ; /opt/uv/bin/uv < buildAccountSetup.ini"
    ssh -l $BUILDUSER $BUILDHOST "rm -f $BUILDDIR/build.out"
    for SRCDIR in $SRCDIRLIST ; do
     echo "`date '+%b %d %T'`       Compiling source code for $SRCDIR" >> $LOGFILE
     ssh -l $BUILDUSER $BUILDHOST "cd $BUILDDIR ; /opt/uv/bin/uv \"BASIC $SRCDIR *\" >> build.out 2>&1" >> $LOGFILE
    STATUS=`ssh -l $BUILDUSER $BUILDHOST "cd $BUILDDIR ; grep \"No Object Code Produced\" build.out | wc -l"`
    if [ $STATUS -gt 0 ]; then
      # Failed to compile one or more programs
      echo "`date '+%b %d %T'`       Failed with $STATUS programs failing to compile. See $BUILDHOST:$BUILDDIR/build.out" >> $LOGFILE
      exit 1
    STATUS=`ssh -l $BUILDUSER $BUILDHOST "cd $BUILDDIR ; grep \"Compilation Complete\" build.out | wc -l"`
    if [ ! $STATUS -gt 0 ]; then
      # No compilation complete? Something bad has happened here
      echo "`date '+%b %d %T'`       Failed with $STATUS programs compiled. See $BUILDHOST:$BUILDDIR/build.out" >> $LOGFILE
      exit 1

    The exit 1 is trapped by CodeDeploy and signals that the BitBucket deployment pipeline has failed. We can then go and review $LOGFILE to determine which program failed compilation or other error(s). Of course, you can interrogate $? from any command and assign it to some variable and act upon that if it is not zero and you need to report the actual error rather then just "exit 1" like I did above.

    Hope this is of some help.

    PS There is no "shell script" language to select for adding code samples so I chose javascript. If the syntax highlighting is off then that is why.

    PPS Can we get "shell script" language added to code samples please?

    Peter Cheney
    Developer and Systems Superstar
    Brisbane Qld Australia