KSH Script

  • Creator
    Topic
  • #47564
    Anonymous
    Participant

      I will be the first to post something, thanks for giving us this space to do so.

      I wrote a monitor for the error database to notify me when transactions exsist.

      Warning First

      First things frist: This is a KSH script, not a tcl. Also you may use this code

      and distribute it anywhere you would like without my consent, however I nor my employer will not be responsible for any mis-use or modifications you decide to make. Use at your own risk!

      Use

      With that being stated:

      This script when ran as a cron job checks the number of lines in the error database. If it contains more than 8 rows ( the normal headers of the db) an e-mail will be created and sent. To setup add your e-mail address to the “to:” variable and place any address in the “from:” variable. The script will complete a long listing of the error and then remove it from the database. The script requires a directory “error” to be created and placed in the same location as the script. A log file with the date.txt will be placed in that directory for review and the e-mail will point you to that location.

      The script requires the following args to be passed:

      $1 = root  (complete path i.e. “/hci/root3.8.1P”)

      $2 = site (site to check i.e. “live”)

      complete call to execute “db_check.ksh /hci/root3.8.1P live”

      To place in cron use something like this to create a log in a dir called logs.  This would have the scritp run 1 min after midnight everyday.

      “01 00 * * * /hcidata_scripts/live/db_check.ksh /hci/root3.8.1P/ live >> /hcidata_scripts/live/logs/db_check.log 2>&1”

      If you have any questions or improvements please post them here so that we all may take advantage of them.

      Code:


      FILEDIR=/hcidata_scripts/live/error
      from= addaddress@yoursite.com
      to= youraddress@yoursite.com
      subject=”$2 – Error Database contains transactions”
      mailfile=`echo “$0” | sed ‘s/.ksh/.msg/1’`

      a=${#*}
      status=1

      if test $a -lt 2
      then
             echo “COMMAND LINE AURGUMENT FORMAT ERROR:”;
      echo “COMMAND LINE AURGUMENT FORMAT ERROR:” >> $mailfile;
             echo “Command Line Format:   “;
      echo “Command Line Format:   ”  >> $mailfile;
             echo “Actual Command Line:  $0 $1 $2”;
      echo “Actual Command Line:  $0 $1 $2”  >> $mailfile;
             status=0;email=1;
      fi

      if [ “$status” -eq 1 ]
       then
         # Save passed arguments
         hciroot=$1
         hcisite=$2
         eval `/hci/bin/hcisetenv -root ksh $hciroot $hcisite`
      fi

         
         lines=`hcidbdump -e | wc -l`
         #echo “Lines: $lines”
         today=`date +%Y%m%d`
         #echo $today

      if [[ “$lines” != “8” ]]
      then
         #pipe the data to a file then remove the transactions
         `hcidbdump -e -D -F -L >> $FILEDIR/$today.txt`
         echo “To:  $to” > $mailfile
         echo “Reply-To:  $to” >> $mailfile
         echo “Subject:  $subject” >> $mailfile
         echo “” >> $mailfile
         echo “ATTENTION CLOVERLEAF DEVELOPERS:” >> $mailfile
         echo “” >> $mailfile
         echo “A Cloverleaf Interface Engine cron job may have found a problem with the Error DB.” >> $mailfile
         echo “Please review the following file for more information:” >> $mailfile
         echo “=====================================================================” >> $mailfile
         echo “The $hcisite error database contains $lines lines, in file $FILEDIR/$today.txt.” >> $mailfile
         echo “=====================================================================” >> $mailfile
        # echo “Script Completed:  c” >> $mailfile
         /usr/sbin/sendmail -f$from -t < $mailfile >/dev/null
      else
         echo “The database did not contain any errors!”
         
      fi

      exit

      [/b]

    Viewing 1 reply thread
    • Author
      Replies
      • #56142
        Brian Goad
        Participant

          Why did it post this message as guest? I was logged in when I started creating it, is there a timeout?

          Brian

        • #56143
          Rick Brown
          Participant

            Brian,

            Didn’t I have you recreate your account a while back?  It may have something to do with that.  Let me know if this continues to be an issue.

        Viewing 1 reply thread
        • The forum ‘Tcl Library’ is closed to new topics and replies.