MySQL Cron job


Want some of my Kool-aid?
I am new to shell scripting and I want to create a cron job that will check to see if mysql is running and if not to start it up. Does anyone have anything like this for another daemon that I can look at or point me to the right direction to find out how to do it myself?
the sort of thing that you can do is to pipe the output of a 'ps' command through 'grep' looking for the daemon that you are concerned with. You can then perform a logical check - if there are no lines then start the daemon up.

C shell can do all this sort of thing, though I haven't used it for a few years so I would need to look up all the syntax.

I didn't get anything of what you just said, I have read some unix books and have heard of pipe, ps, and grep, but I have no idea on how to use them together. I was hoping more for a tutorial link or an example that I could discect and learn from. Thanks for the help anyways :)
ps -Uroot | grep 'mysqld' seems to do the trick for seeing if there's a mysqld process running. Not sure about the logical syntax with shell scripting... I've only just recently picked up a book, Linux Shells by Exampe (Ellie Quigley), and so haven't gotten to far... but already I'm able to do that. :) Give it a try--seems like a good text.
The logical test syntax is fairly simple:

if <logical test>
then <action commands>

Just notice the 'fi' to close the 'if' structure (though I believe you can use 'endif' as well). Based upon the previous example I would probably look at the length of the string returned from the grepped ps statement. If it is over a certain length then mysql will be running. There may be better commands to pick out whether the text mysql is in the string somewhere (perl is good for this) but the length thing is a quick fix that works quite well.

Sorry....not on my machine so I cannot test out the length stuff yet.