cron / crontab issues - solaris 10

I am having some issues with my cronjobs not running in solaris 10.

Cron is running:

~> ps -ef | grep cron
root 202 1 0 Jul 18 ? 0:01 /usr/sbin/cron
bender 1646 1562 0 01:57:49 syscon 0:00 grep cron

crontab -l lists the cronjob and I *think* its in the correct format :stuck_out_tongue:

~> crontab -l
#ident "@(#)bender 1.5 92/07/14 SMI" /* SVr4.0 1.2 */
#
0 * * * * /usr/local/apache2/htdocs/wootget2

Script works perfectly fine when run manually from terminal. It's just not executing by cron.

Also I had to create/edit the entry in
~> ls /var/spool/cron/crontabs/bender
-rw-r--r-- 1 root root 121 Oct 28 00:16 /var/spool/cron/crontabs/bender

because when i do a crontab -e
it seems to act wierd. When I do crontab -e
it automatically enters a # on a new line, then if i try to add a new line it gives me a ? and doesnt seem to do anything or recognize any commands.

~> crontab -e
121
0 * * * * /usr/local/testcron
?
^C
?
:q
?
:w
?
:x
?
^Z
[1]+ Stopped crontab -e

that's 'ed' you are running there. If you don't much like it (can't say I blame you), try setting the EDITOR environment variable to your favourite editor.

In my case, that would be:

EDITOR=vi
export EDITOR
crontab -e

---------- Post updated at 08:11 PM ---------- Previous update was at 08:09 PM ----------

Oh and btw, to quit out of ed, the command is 'q' (no ':' symbol in front)

Thanks, that fixed the editing part, however my cron job still isn't working :frowning:

Hmm, editing then saving should have activated to correctly... I'll read a little more then...

---------- Post updated at 08:19 PM ---------- Previous update was at 08:16 PM ----------

Is there any error in your cron log file? Does it show it executing?
Generally a cron job problem is caused by the environment being wrong in the script - things like your path etc are not set by cron, so something that works from your commandline might not from cron.

Have you checked the user's email? Cron sends an email containing stdout and stderr if the script produces any output.

it seems to recognize that this is a cron job, I get this when editing

bender@bender:~> crontab -e
"/tmp/crontabHzaysd" 3 lines, 121 characters
#ident "@(#)bender 1.5 92/07/14 SMI" /* SVr4.0 1.2 */
#
0 * * * * /usr/local/apache2/htdocs/wootget2
~
:q
The crontab file was not changed.

---------- Post updated at 02:24 AM ---------- Previous update was at 02:21 AM ----------

Ok, it is working now.
After changing the editor to vi like you said, then I edited the crontab, saved, edited it back to normal and saved it again. Now it is working.

But to your other question, I do not have a cron log (would like to turn it on) and when it started working, it sent me an email to my user, however when it was not working, it sent nothing.

The cron log will be in there.
(from memory) try the following file: /var/cron/log

It shows start and finish of each cron job and indicates if any fatal errors occurred.

Before you used crontab to edit it, cron didn't know to reread your /var/spool/cron/crontabs/bender file again - a restart of cron (or a reboot) probably would have done the trick too, or it could have happily replaced your crontab with what it had in memory - YMMV :slight_smile:

Ok, checked the cron log, it was in /var/cron/log (i was told it should have been /var/log/cronlog or something like that)

and the cron log shows nothing until the job that worked... nothing logged for 24 hours until the job worked.

> CMD: [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean
> root 1141 c Tue Oct 27 03:30:00 2009
< root 1141 c Tue Oct 27 03:30:00 2009
> CMD: /usr/local/apache2/htdocs/wootget2
> bender 1715 c Wed Oct 28 02:22:00 2009
< bender 1715 c Wed Oct 28 02:22:02 2009

is the script woodget2 having executable permissions ?. Many times we people forget to give that.

Cron isnt at fault here, the script is. Have you remembered that cron does not read profiles and does not have any user environmental settings ?? Any script that runs should assume this and define any variabvles, home directories. Ive just had a similar problem with a DBA who wrote a few scripts and nothing worked. "Cron is broken" was his loud cry accross the room.

Well, turns out his script didnt set any variables or paths so commands werent found and the script never ran.

What I suggest you do is have a play, run the script in verbose mode :-

#!/bin/ksh -v or -x

,

Then re-direct the output of the file, within the script, to a file

exec 1>> /tmp/script-output.txt
exec 2>&1
exec 3>&1

or adjust the cron entry to redirect output from the script :-

0 * * *  * /path/to/script/script  >/tmp/script-output.txt 2>&1

Definately a script issue.

Cheers

SBK