LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-27-2009, 04:07 AM   #1
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
shell script to check whether mysql server is running or not


hi all...

from nmap localhost | grep mysql command i will come to know whether mysql server is running or not....

my problem is i want to test whether mysql server is running or not in shell script and if it is running i need to tell the user to stop the server to run the shell script...


while [ `nmap localhost | grep mysql`=='3306*' ]
do
echo mysql is running stop the server and then run the script
exit 1
done


this is giving me error as binary operator expected...

can anyone help me please....

Thanks in advance..
 
Old 04-27-2009, 04:24 AM   #2
vitalstrike82
Member
 
Registered: Oct 2007
Location: Singapore
Distribution: OpenSuse, Slackware, Redhat
Posts: 315

Rep: Reputation: 40
You can check if ur mysql server is running by inputing this command:

Code:
/usr/local/mysql/bin/mysqladmin ping
Provided that your mysql is install in /usr/local/ path

if it replies, sqld is alive, then it is running.

If your mysql is not found in the path which is same as mine, you can issue these commands to find your package

Code:
whereis mysqladmin
or use this command to find where your mysql package is install:

Code:
most /var/log/packages/<package_name>

Last edited by vitalstrike82; 04-27-2009 at 04:25 AM.
 
Old 04-27-2009, 04:36 AM   #3
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Original Poster
Rep: Reputation: 55
thanks... yes thats fine..i will come to know whether mysql server is runnning or not ..but i have to check it in if statement ...if server is running i have to tell the user to stop the server...

nmap localhost will tell whether mysql server is running or not but how to check it inside the if statement..

please help me iam very new to linux....
 
Old 01-18-2011, 08:39 AM   #4
zjoske
LQ Newbie
 
Registered: Dec 2009
Posts: 18

Rep: Reputation: 2
as superuser you can use the `service` command:
service mysql status

In a script as superuser you might do something like:

#!/bin/ksh
if [[ `service mysqld status | grep running ` -eq 0 ]]
then
echo mysql running
else
echo mysql not running
fi


If you are not root you might considder something like:

#!/bin/ksh
if [[ `ps -ef | grep mysqld | grep -v root` -eq 0 ]]
then
echo mysql running
else
echo mysql not running
fi
 
1 members found this post helpful.
  


Reply

Tags
mysql


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
run a shell script on remote client from a server to find all its running process robin singh Linux - Newbie 7 10-03-2008 11:32 AM
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 09:56 AM
running a shell script which invokes another shell program!!! raghu123 Programming 1 08-04-2008 09:10 AM
How to check if NAS is mounted via shell script? koobi Programming 13 01-12-2008 10:07 AM
script to check instance of PHP & mySQL running on Unix platform kushalkoolwal Programming 7 04-26-2006 09:40 PM


All times are GMT -5. The time now is 07:41 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration