Operating System - HP-UX
1748019 Members
4521 Online
108757 Solutions
New Discussion

Re: crontab for certain user doesn't work

 
petrbena
Occasional Advisor

Crontab for certain user doesn't work

Hi, I am unable to create a job for certain user (oracle), this user is in /usr/lib/cron/cron.allow, cron service is running and work for other users (such as root), the crontab file is in /usr/spool/cron/crontabs as expected. The crontab log has entry for each execution but the file is NOT executed.

 

I inserted to beginning of script:

 

#!/bin/sh

echo `date` >> /some/path/log

 

(where /some/path is a path for log file), when I start the script from terminal it create an entry in this log file, it never creates an entry when it is running from cron, therefore the script isn't executed.

 

Is there a way to check why it happens?

 

This is a log from cron:

>  CMD: /usw/app/oracle/admin/CRMISEF1/statspack/test.sh >> /usw/app/oracle/admin/CRMISEF1/statspack/sh.log 2>/dev/null
>  oracle 21019 c Mon Oct  8 15:58:00 METDST 2012
<  oracle 21019 c Mon Oct  8 15:58:00 METDST 2012 ts=9

15 REPLIES 15
Matti_Kurkela
Honored Contributor

Re: Crontab for certain user doesn't work

First, remove the "2>/dev/null" from the end of the cron job specification. By redirecting the standard error output to /dev/null, you are destroying the error message that would tell you more about the problem.

 

After removing the "2>/dev/null" part, the cron will gather any error messages the script produces and send them as email to the oracle account. (The email file will be /var/mail/oracle by default; if you don't want to use a real email application, you can read it directly with "more" or similar.)

 

Alternatively, you could replace the "2>/dev/null" part with something like "2>/usw/app/oracle/admin/CRMISEF1/statspack/sh.errorlog", which would redirect the error messages to the file of your choice.

 

MK
Dennis Handly
Acclaimed Contributor

Re: crontab for certain user doesn't work

>echo `date` >> /some/path/log

 

(You do know you can just use: date >> /some/path/log)

 

>it never creates an entry when it is running from cron, therefore the script isn't executed.

 

Then there must be something wrong with your .profile?  You might want to change your line to:

#!/bin/sh -x

 

(And make sure you don't send stderr to /dev/null as Matti said.)

 
><  oracle 21019 c Mon Oct  8 15:58:00 METDST 2012 ts=9 

 

This says you got exit status 9.

petrbena
Occasional Advisor

Re: crontab for certain user doesn't work

Thank you,

 

I removed the part as you mentioned:

 

>  CMD: /usw/app/oracle/admin/CRMISEF1/statspack/test.sh >> /usw/app/oracle/admin/CRMISEF1/statspack/sh.log
>  oracle 22478 c Tue Oct  9 10:02:00 METDST 2012
<  oracle 22478 c Tue Oct  9 10:02:01 METDST 2012 ts=9

/export/home/oracle$ mail
No mail.

 

there is no entry in /usw/app/oracle/admin/CRMISEF1/statspack/sh.log please note that test.sh contains only 2 lines:

 

#!/bin/sh

date >> /usw/app/oracle/admin/CRMISEF1/statspack/sh.log

Matti_Kurkela
Honored Contributor

Re: crontab for certain user doesn't work

> /export/home/oracle$ mail
> No mail.

 

Has someone redirected the mail of the oracle user somewhere else?

 

Does /export/home/oracle/.forward file exist?  If it exists, read the file to find out where the oracle user's mail goes.

Also check /etc/mail/aliases. Does it mention "oracle"? If you modify /etc/mail/aliases, remember to run "newaliases" after modifications.

MK
petrbena
Occasional Advisor

Re: crontab for certain user doesn't work

No, it's not redirected, but I think there is some problem with mail delivery, because despite there were some emails on oracle, I am unable to deliver emails to anyone on that machine, for example

cofftz01:/#mailx oracle
Subject: test
this is test
.
EOT

/export/home/oracle$ mailx
No mail for oracle
Matti_Kurkela
Honored Contributor

Re: crontab for certain user doesn't work

Please run "bdf". Is your /var or /tmp filesystem 100% full?

If /var is full, it will certainly cause email issues, and might cause some issues to cron too. Since the system logs are written to /var by default, having it 100% full would mean your logs may be incomplete, making troubleshooting harder.

 

If /tmp is full, it will cause many things to fail.

 

You might also want to look at /var/adm/syslog/mail.log, to get more information on email errors.

MK
Dennis Handly
Acclaimed Contributor

Re: crontab for certain user doesn't work

>there is no entry in /usw/app/oracle/admin/CRMISEF1/statspack/sh.log please note that test.sh contains only 2 lines:

 

Redirect stderr to the same logfile in crontab, that way you don't need mail: 2>&1

Also add -x as I mentioned.

 

>date >> /usw/app/oracle/admin/CRMISEF1/statspack/sh.log

 

No need to redirect this if the cron output is also going there.

 

 

petrbena
Occasional Advisor

Re: crontab for certain user doesn't work

/tmp is 70%

/var is 74%

 

 Log from cron after changing the path:

 

>  CMD: /usw/app/oracle/admin/CRMISEF1/statspack/test.sh 2>&1
>  oracle 29430 c Wed Oct 10 12:08:00 METDST 2012
<  oracle 29430 c Wed Oct 10 12:08:00 METDST 2012 ts=9

I didn't change /bin/sh to /bin/sh -x but I doubt it would do anything since the script is clearly not even loaded

Ralf Seefeldt
Valued Contributor

Re: crontab for certain user doesn't work

Hi petrbena,

 

Are there emails for the cronjobs of your other users?

What shells are listed in /etc/shells?

Have you tryed to only enter a command in the crontab instead of a script? (46 14 * * * date > /tmp/foo )

How did you execute the script from the CLI and as which user?

Do the environment variables (exp. $PATH) of user oracle look fine?

What are the ownership and permissions of your scriptfile?

 

Bye

Ralf