System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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

petrbena
Occasional Advisor

Re: crontab for certain user doesn't work

Hi, thanks

 

The result of date is:

 

>  CMD: date >> /usw/app/oracle/admin/CRMISEF1/statspack/sh.log
>  oracle 8516 c Wed Oct 10 16:48:00 METDST 2012
<  oracle 8516 c Wed Oct 10 16:48:01 METDST 2012 ts=9

the command wasn't executed as expected

 

The path is:

PATH=/usr/bin:/usr/bin:/opt/ansic/bin:/usr/ccs/bin:/usr/contrib/bin:/opt/hparray/bin:/opt/nettladm/bin:/opt/upgrade/bin:/opt/fcms/bin:/opt/pd/bin:/usr/bin/X11:/usr/contrib/bin/X11:/opt/mx/bin:/opt/resmon/bin:/opt/perf/bin:/opt/prm/bin:/opt/scr/bin://opt/perl/bin:/opt/ignite/bin:/opt/graphics/common/bin:/usr/sbin/diag/contrib:/opt/OV/bin/OpC:/opt/langtools/bin:/opt/imake/bin:/sbin/fs/vxfs3.5/bin:/usr/symcli/bin:/opt/ssh/bin:/opt/wbem/bin:/opt/wbem/sbin:/opt/gwlm/bin:/usr/local/bin:/opt/networker/bin:/opt/sfm/bin:/opt/CA/eTrustAccessControl/bin::/opt/CA/eTrustAccessControl/bin::/usw/app/oracle/product/8.1.7_64bit/bin:/usr/bin:/etc:/usr/ccs/bin:/usr/local/bin:/usr/sbin:/sbin:bin:.

there is no /etc/shells on that system

 

I executed the command using sh shell in terminal (over ssh), I just executed it from its directory (./test.sh) - that worked

but it doesn't work from cron

 

the permissions are 755

 

petrbena
Occasional Advisor

Re: crontab for certain user doesn't work

the user I used to execute was oracle, and regarding emails, I don't think there are any email for any users on that box. It seems that mails just don't work
Dennis Handly
Acclaimed Contributor

Re: crontab for certain user doesn't work

>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

 

The script should be loaded and the -x processed.  I suspect it is dying in your .profile processing.  That -x may give you a clue.  Provided you redirect stderr to a file so we can ignore your mail issue.

petrbena
Occasional Advisor

Re: crontab for certain user doesn't work

I inserted -x option - to #!/bin/sh -x the cron log is still same:

 

>  CMD: /usw/app/oracle/admin/CRMISEF1/statspack/test.sh 2>&1
>  oracle 29277 c Tue Oct 16 10:04:00 METDST 2012
<  oracle 29277 c Tue Oct 16 10:04:00 METDST 2012 ts=9

keep in mind that even if I use simple date command, it fail

 

 

Dennis Handly
Acclaimed Contributor

Re: crontab for certain user doesn't work

>cron log is still same

 

Of course, since your mail isn't working.  You need to put back the redirection of the output:

/usw/app/oracle/admin/CRMISEF1/statspack/test.sh >> /usw/app/oracle/admin/CRMISEF1/statspack/sh.log 2>&1

 

Then look into sh.log.

cradules
Occasional Visitor

Re: crontab for certain user doesn't work

Hi,

I got to this post having same issues. First I did not realize what happend but rethiking my steps I found my cause.

I have set the cron for a user on certain of numbers of servers. To avoid login each server, I just created a script to do that for me on all server. The idea was to insert the cronjob onto /var/spool/crontabs/$user. That user had no cronjob setup before so this was first time the file was created.

From here the owner and permisions of the crontab were worg.  The file was 644 and the user was root and the group was main group of the root user (using sudo for inserting the conjob into the file)

Soon I have change the permisions to 400 and owner root with user's group (and ofc user part of cron.allow) the cron for the user started to work.

 

I am not sure if  this is going to help you, but I thought is worth to mention it.

 

Regards,