Click to See Complete Forum and Search --> : HP-UX 11 and Cron


Icarus
09-30-2002, 05:15 PM
Had an odd probelm with a cron job script this morning that baffles me of why...

I've been using a script for months to clean out a bunch of log files, some of which tend to become huge after a while (largest gets to 54MB after 2 months).

The script has been giving me no problems so I decided to add it to cron so I don't have to remember to run it every month or two. And last night was the first time it ran via cron...

it ran into some kind of error and proceeded into a loop of mailing errors to root. These mailings are relayed to the Exchange server and then to the mailboxes of me and my supervisor. He got into work 15 minutes before I did (normal) and found 33000 emails from cron:eek:

He called me as I was just about there and told me 'something is not right' :)

I ended up having to kill cron to stop it generating the messages and manually removing over 6000 remaining messages from the /usr/spool/mqueue...

The script is set to run /usr/sh and cron runs scripts with sh so I don't see where it blew up...here's how the script starts
##!/usr/sh

cd /usr/tmp

#compress the jobs log files
gzip -v CreditCd.log
gzip -v Priority.log
gzip -v cst.log
gzip -v cst1.log
gzip -v cst2pm.log
I notice that I have ## at the begining...I don't know why, see that as being bad??

the error messages were...
/usr/sbin/logclean.sh[6]: gzip: not found.
...
...
...
mv: CreditCd.log1.gz: cannot access: No such file or directory
....
The mv is later in the script, I've check for permission problems (none) and if it wasn't in /usr/sbin it would of not been able to start it in the first place...

Is my script FUBAR or is it a probelm with cron running it for some reason...I thought that cron ran scripts as root

bastard23
10-03-2002, 01:15 PM
mahdi,
First off, I've never really run HPUX, so here are some educated guesses. It looks like the problem is that it can't find 'gzip'. Figure out where gzip is located and then figure out the PATH coming from cron. What does the crontab file look like for root? (It only needs to be root if the logfiles are owned by root.) You can also hard code the path, i.e. /usr/local/gnu/bin/gzip, but you should figure out the PATHs first.
33000 emails, WOW, how often is the script supposed to be running? If the crontab entry is setup for once a day, there may be some other weirdness with cron. I don't know.

##!/usr/sh
This won't use /usr/sh as a shell. Your probably using /bin/sh or somesuch, which is started by cron to run your script. Two pound symbols will make it a mere comment. Also /usr/sh seems a little weird (but I don't run HPUX), you might want to check that.

Hope that helps,
chris

PS If you are still having problems, post the output to `crontab -l`

PPS edited because I accidently posted before I was done.