Operating System - HP-UX
1753511 Members
5457 Online
108795 Solutions
New Discussion юеВ

reset of apache fails in crontab, but works via at job.

 
SOLVED
Go to solution
Steve Post
Trusted Contributor

reset of apache fails in crontab, but works via at job.

My reset_apache shell script does not work when running via a root crontab file.
run by hand: works
run by at job: works
run by batch: works
run by daemon process: works
run by crontab job: fails
run by crontab to run batch job: fails
run by crontab to run at job: fails

I have apache on an hpux11 hp9000 (trusted system). This version of apache uses php and connect to a sybase database via sybperl module. The shell program stops apache, and restarts it after 10 seconds. Apache resets. But the sybase connection is missing.

It seems weird that at and batch work but crontab doesn't. Any ideas?
Steve Post
9 REPLIES 9
Vincenzo Restuccia
Honored Contributor

Re: reset of apache fails in crontab, but works via at job.

Check /var/adm/cron/log
Juan Gonz├бlez
Trusted Contributor

Re: reset of apache fails in crontab, but works via at job.

Hi, could you attach your script.

Best Regards
JGM
Steve Post
Trusted Contributor

Re: reset of apache fails in crontab, but works via at job.

Nope. Not attaching the script. Too big. But here is the cist of it....
#!/bin/ksh
cd /disk1/apache/mac/bin
./apachectl stop
sleep 10
./apachectl start

The apache has sybperl2.13 and php embedded DEEP inside it.

I looked at the log files. They don't show anything wrong (just the time apache gets reset).
Juan Gonz├бlez
Trusted Contributor
Solution

Re: reset of apache fails in crontab, but works via at job.

Hi Steve,
cron doesn't store enviroment information (PATH, HOME, ..) so try:
#!/bin/ksh
cd /disk1/apache/mac/bin
/disk1/apache/mac/bin/apachectl stop
/usr/bin/sleep 10
/disk1/apache/mac/bin/apachectl start

Good Luck
JGM


Victor BERRIDGE
Honored Contributor

Re: reset of apache fails in crontab, but works via at job.

Hi Steve,
I agree with Juan's point of vue:
You may have env variables that are set when you try, and missing for cron...
Set them in your script...

Good luck

Victor
Steve Post
Trusted Contributor

Re: reset of apache fails in crontab, but works via at job.

Yes. I agree I need to make sure I have the correct environmental variables in the script. Alas, I already did that. As root at a terminal I shoved the results of env into the top of the script. ....no change.

If this was the really problem why would it work with at and batch but not cron? Do they run with different environments normally? My guess is there is some type of permissions problem. Some unknown cron-thing tries to use additional files that at and batch don't care about. My next try is to output the environment variables to a text file via at-job, batch-job, and crontab-job, THEN see if there is a difference in the 3 files.
I'll let you know. Steve
Steve Post
Trusted Contributor

Re: reset of apache fails in crontab, but works via at job.

Ok. I ran my test. File /testenv has one line in it: "env".

at now +1 minute </testenv > /tmp/env.at
DO
batch </testenv > /tmp/env.batch
DO
and in the
17 * * * * /testenv > /tmp/env.cron
The /tmp/env.cron file (cron's environment), is only 5 lines. The key variable missing is $SYBASE. This is required by sybperl to make success sybase connections in apache. So, this looks like the problem.

Now, why did it not work when I put the entire environment in the file before? I'll figure it out. I bet the SYBASE variable was set, but not exported. So, when apache started, it lost that SYBASE value.

Why are most of the evironmental variables missing when running cron vs at/batch? I'll be able to figure it out by looking at where they are set normally, and checking permissions. But, I'm not worried about it.

Thanks folks. Steve

Juan Gonz├бlez
Trusted Contributor

Re: reset of apache fails in crontab, but works via at job.

Hi,
just a note ( from at(1) ):

An at or batch job consists of a two-part script stored in /var/spool/cron/atjobs that can be executed by the POSIX shell.

The first part sets up the environment to match the environment when the at or batch command was issued. This includes the current shell environment variables, current directory, umask, and ulimit. Open file descriptors, traps, and priority are lost.

The second part consists of the commands that you entered.

When cron dispatches the job, it starts a POSIX shell to execute the script.

Best Regards
JGM
Steve Post
Trusted Contributor

Re: reset of apache fails in crontab, but works via at job.

Thank you Juan.
That makes a lot more sense now. The environment was as of my telnet session. If I run at now+5 minutes<echo testing
DO
I can find that file /var/spool/cron/atjobs has 40 lines of UNIX environment and the last line is the "echo testing."