Script Problem

Gerard Seibert gerard at seibercom.net
Sat Dec 17 11:13:09 PST 2005


Using FreeBSD 5.4

Please do not laugh. I absolutely suck at writing scripts. Someday I
might learn, but in the mean time, I need some assistance.

I want to run a script from CRON that will check to see if MySQL is
running, and if not, restart it. I have had a problem with MySQL
shutting down unexpectedly.

This is my first attempt at writing the script.

#!/bin/sh
if  (`ps -wxuU mysql | grep -o  mysqld_safe`)
        then
        echo "MySQL is Running"
                else
                /usr/local/etc/rc.d/mysql-server.sh restart
                echo "MySql Server is Restarted"
fi

That produces this output even though MySQL is running.

A mysqld process already exists
Stopping mysql.
Waiting for PIDS: 47567, 47567.
Starting mysql.
MySql Server is Restarted

If I stop MySQL and then run the script, I get this output.

mysql not running? (check /var/db/mysql/seibercom.net.pid).
Starting mysql.
MySql Server is Restarted

Obviously, I do not know what I am doing. Perhaps someone could help me
with this.

Ciao
-- 
Gerard Seibert
gerard at seibercom.net



More information about the freebsd-questions mailing list