tags:

views:

77

answers:

2

I have a cron job set up that will start my script.

The intent of this script is to kill a process that is currently running, and start up a new version of this process (CHECKDB). CHECKDB needs to be running all the time, so we have a start_checkdb script that is basically a infinite loop that runs CHECKDB; if it crashes, it stays in the loop, starts it again. [yes, i realize that isn't the best practice, but that's not what this is about]

My script will be called by cron without issue, and then it will kill CHECKDB without issue. As far as I can tell, the child script gets called that starts CHECKDB back up, but every time I check ps after the cron runs, the process is not running. If I run the script by hand on the command line, under any shell, it works no problem: kills CHECKDB and start_checkdb, starts up start_checkdb which starts up CHECKDB.

Yet for some reason, when cron does it, the process is never running afterwards. It kills the live one, and either doesn't start it, or it starts it and kills it.

Is it possible that when cron comes to the end the parent process, it will kill the child processes that were called?

I don't know if it makes a difference, but this is on Solaris 8.

A: 

You might look at using nohup inside your cron script, when launching checkdb. Some thing like 'nohup command &' would be a normal way to launch something you wanted to live beyond the launching process.

Andrew B
Well, I tried to do this, but it didn't work. It terminated the process when cron ran it and didn't terminate when running manually. This is very frustrating :(
CB
Nohup just masks the hangup signal. It's used to prevent a program that you launched from a tty (terminal) from exiting when you log out.
Kenster
A: 

Could you clarify your description of the arrangement? It sounds like, under normal circumstances both start_checkdb and CHECKDB are running. The cron job is supposed to kill CHECKDB, and the already-running copy of start_checkdb is supposed to restart it? Or does the cron job kill both processes and then restart start_checkdb? After the cron job runs, which process is missing--CHECKDB, start_checkdb, or both?

Having said that, the most common reasons for a process to work from the command line but fail from cron are:

  • Dependency on the correct command PATH (or some other environment variable)
  • Dependency on being run from the correct directory
  • Dependency on being run from a tty.
Kenster