MySQL Forums
Forum List  »  Knowledge Base

Trouble with running a shell script
Posted by: Geeta Rajaraman
Date: August 25, 2010 02:13AM

Hello there -
I've been trying to create a simple "check" script, that tries to insert and delete a row into the database, just to check general database health.
It looks something like this:
------------------
DBNAME="$1"
USER="$2"
PASSWORD="$3"
TABLENAME="$4"
MYSQL_HOME=/var/lib/mysql/db_5.1.47

# Try to determine MYSQLHOME
if [ -z "$MYSQL_HOME" ]
then
MYSQL_HOME="$(egrep ':(Y|N)$' /var/lib/mysql/mysqltab | head -n 1 | cut -d: -f2)"
fi

if [ -z "$MYSQL_HOME" ]
then
echo "MYSQL_HOME not set, also cannot determine that from /var/lib/mysql/mysqltab." >&2
exit $STATE_UNKNOWN
fi

export MYSQL_HOME

MYSQL="$(which mysql)"

if [ ! -x "$MYSQL" ]
then
echo "Cannot find mysql in $MYSQL" >&2
exit $STATE_UNKNOWN
fi

AUTHENTICATION="-u$USER -h localhost -p$PASSWORD"

OUTPUT=$(mysql $AUTHENTICATION $DBNAME -e "INSERT INTO $TABLENAME(a) VALUES(3);DELETE FROM $TABLENAME")

echo $OUTPUT

---------------

But, OUTPUT is always empty. I wanted to see something like "1 row affected" which would let me process a conditional query that can check for database health issues.

Can someone please help me with this ? I'd like to know what I'm doing wrong.

Thanks much

Options: ReplyQuote


Subject
Views
Written By
Posted
Trouble with running a shell script
1426
August 25, 2010 02:13AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.