[thelist] Shell scripting help

Anthony Baratta Tony at IdeaSystems.com
Mon Aug 7 10:22:58 CDT 2000


At 08:44 AM 8/7/2000, you wrote:

>      Can anyone help me write a shell script for my unix box?  What I am
>      trying to do is have a script connect to a mysql server and verify
>      that it is up.  If it is not up then send and email to me.  Sound
>      pretty simple, but I don't know how to even get started.


do a mysql -V and cut and paste the answer to the $varExpected variable.
find your full path the mysql (whereis mysql) and cut and paste the answer 
into $varMySQLexe. find your Sendmail executable and put the full path into 
$varSendMail. lastly, put your email address into $varContact.

Might need a little debugging, but should get you started.

#!/usr/bin/perl
#
#

$varExpected = "mysql  Ver 9.32 Distrib 3.22.21, for pc-linux-gnu (i686)";
$varMySQLexe = "/usr/local/mysql/bin";
$varSendMail = "/usr/sbin/sendmail -t -n"
$varContact = "emergency at email.com"

$varFound = `$varMySQLexe/mysql -V`;
$varDate = `date`;

if ($varExpected != $varFound) {
         open (MAIL, "| $varSendMail") || print "cannot open mail program";
         print MAIL "To: $varEmailTech \n";
         print MAIL "From: mySQL_Cron_Job \n";
         print MAIL "Subject: Can not find mySQL daemon\n\n";
         print MAIL "At $varDate.\n\n";
         print MAIL "Cron found $varFound.\n\n";
         print MAIL "Cron expected $varExpected.\n\n";
         print MAIL " \n\n";
         close(MAIL) || print "mail pipe exited $?";
}

end'


----
Anthony Baratta
Isys Idea Systems

voice 510-452-4554
fax 510-452-4641





More information about the thelist mailing list