LinuxQuestions.org
Visit Jeremy's Blog.
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 06-05-2006, 05:32 AM   #1
asheesh.tyagi
Member
 
Registered: Apr 2005
Location: Delhi,India
Distribution: Red Hat
Posts: 35

Rep: Reputation: 15
runing commands


Is there any way of executing a command automaticaly if it dies.i run a command
'mysql -u --password=xxxxxxx logs </var/log/mysql.pipe &' and it dies after 2-3 days.
can anyhow status of a command be checked and if it is not running then can it be executed
automaticaly.
 
Old 06-05-2006, 05:40 AM   #2
prozac
Member
 
Registered: Oct 2005
Location: Australia
Distribution: slackware 12.1
Posts: 753

Rep: Reputation: 32
write a script that checks for the status of the command and re-launches it if already dead and put it in crontab to run automatically as often as you like.
 
Old 06-05-2006, 11:57 AM   #3
asheesh.tyagi
Member
 
Registered: Apr 2005
Location: Delhi,India
Distribution: Red Hat
Posts: 35

Original Poster
Rep: Reputation: 15
how can i check the status of command
'mysql -u --password=xxxxxxx logs </var/log/mysql.pipe &' in a script.
 
Old 06-05-2006, 06:39 PM   #4
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 57
Code:
while true; do
  mysql -u --password=xxxxxxx logs </var/log/mysql.pipe
done
That will loop forever starting MySQL but without the ampersand at the end to background it there will only ever be one instance running at a time.
 
Old 06-06-2006, 04:02 AM   #5
asheesh.tyagi
Member
 
Registered: Apr 2005
Location: Delhi,India
Distribution: Red Hat
Posts: 35

Original Poster
Rep: Reputation: 15
if i run the command
'mysql -u --password=xxxxxxx logs </var/log/mysql.pipe' (without &)while a process of this command is allready running in the background ,it start a new process of this command. output of ps is
root 16886 0.1 0.0 3668 1244 pts/27 S 13:16 0:00 /opt/mysql/bin/mysql -u root --password=x xxxxxx syslog
root 16946 0.0 0.0 5184 1240 pts/27 S 13:23 0:00 /opt/mysql/bin/mysql -u root --password=x xxxxxx syslog

so if a run this command from a loop.will it not create another instances.please help

Thanks
 
Old 06-06-2006, 04:49 AM   #6
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 57
Kill the current instance then run the loop. How hard was that? You're without a MySQL server for all of about 3 seconds if you're quick.
 
Old 06-06-2006, 05:15 AM   #7
ethics
Senior Member
 
Registered: Apr 2005
Location: London
Distribution: Arch - Latest
Posts: 1,522

Rep: Reputation: 45
Assuming he is sitting infront of it all day?

I wish i could get paid for restarting a process all day .
 
Old 06-06-2006, 06:26 AM   #8
prozac
Member
 
Registered: Oct 2005
Location: Australia
Distribution: slackware 12.1
Posts: 753

Rep: Reputation: 32
when i did this
Code:
$ ps aux  |grep /usr/local/mysql
i got this in my system
Quote:
mysql 585 0.0 1.2 49596 1616 ? S Mar31 0:14 /usr/local/mysql/
maybe you can do this with a script
Code:
ps aux |grep /usr/local/mysql
if [ "$?" == "1" ]; then
   launch mysql again;
fi
and put it in your cron to run every minute or hour as you like.

[EDIT]
it seems
Code:
$ ps aux  |grep /usr/local/mysql
returns 0 even when there is no actuall mysql process running. it shows me this
Quote:
root 2829 0.0 0.3 4488 672 pts/0 S+ 16:21 0:00 grep /usr/local/mysql
maybe you can grep for process id instead. when the process starts awk its process id and save it and check for the same id next time. if its not there just loop the whole process else sleep. maybe it will work. i am not trying!
[/EDIT]

Last edited by prozac; 06-06-2006 at 06:41 AM.
 
Old 06-07-2006, 08:21 AM   #9
asheesh.tyagi
Member
 
Registered: Apr 2005
Location: Delhi,India
Distribution: Red Hat
Posts: 35

Original Poster
Rep: Reputation: 15
Thanks everybody
I have created a script and put this code in it
while true; do
mysql -u root --password=xxxxxxx logs </var/log/mysql.pipe
done

and ran it. it is working. now whenever this process get killed a new process get started automatically.
 
Old 06-07-2006, 08:28 AM   #10
asheesh.tyagi
Member
 
Registered: Apr 2005
Location: Delhi,India
Distribution: Red Hat
Posts: 35

Original Poster
Rep: Reputation: 15
prozac if i run ps aux |grep /usr/bin/mysql and then echo $? it will always give 0 because command
ps aux |grep something
will allways run successfully whether it find a process or not.

so variable $? will allways contain 0 (for successfully running command).

Last edited by asheesh.tyagi; 06-07-2006 at 08:30 AM.
 
  


Reply


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
Runing commands in the background juanb General 4 09-22-2005 09:53 AM
how to know shorewall is runing? shams Fedora 2 12-26-2004 10:41 AM
runing the make command Paridoth Mandriva 4 10-30-2004 06:57 PM
Runing standalone DNS ivanatora Linux - General 2 10-13-2004 09:12 AM
runing .out files What Gives? 1337 Twinkie Fedora 4 07-27-2004 12:00 AM


All times are GMT -5. The time now is 02:22 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration