3 Replies Latest reply on Nov 3, 2017 3:19 PM by stuieordie

    Run a BASH Mysql query in the Linux/Unix script monitor

    jburke

      Having a hard time getting this to work. The script runs correctly locally but when I try to get it to work in the Linux/Unix script monitor it says "mysql: command not found". What I need to do is to get the creation dates from the tables on two servers that are replicated and verify they are within a certain time frame and send an alert if they are not. We tried using the seconds_behind_master value in Mysql but that was not showing the time difference correctly. The tables were 20 minutes separated in dates but the seconds_behind_master value was 0 so we need to do a comparison to verify the times.

       

      Here's a simplified version:

       

      #!/bin/bash

      HOST1=Host1

      HOST2=Host2

      DB_USER=User

      DB_PASSWD=Password

       

      CREATE_DATE_HOST1=`mysql -N -u ${DB_USER} -p${DB_PASSWD} -h ${HOST1} -e "select create_date, unix_timestamp(create_date) from <table> order by id desc limit 1" | awk '{print $3}'`

      CREATE_DATE_HOST2=`mysql -N -u ${DB_USER} -p${DB_PASSWD} -h ${HOST2} -e "select create_date, unix_timestamp(create_date) from <table> order by id desc limit 1" | awk '{print $3}'`

      SECONDS_DIFF=`expr $CREATE_DATE_HOST1 - $CREATE_DATE_HOST2`

       

      echo "Statistic.1: "$CREATE_DATE_HOST1

      echo "Statistic.2: "$CREATE_DATE_HOST2

      echo "Statistic.3: "$SECONDS_DIFF

      exit 0

       

      I've been beating this around all day and haven't gotten any closer to getting the MySQL values out of it...

      Any ideas on what I am missing?

      Thanks

      -Jim