1825793 Members
2297 Online
109687 Solutions
New Discussion

cron error

 
Elif Gius
Valued Contributor

cron error

It has been my impression for some time now that any scripts written to
be CRONned has to be sh shell scripts, like so;

#!/bin/sh

If the script is based on a shell other than sh, e.g. C shell or Korn
shell, then the appropriate CRON entry should be

* * * * * /usr/bin/ksh
or

* * * * * /usr/bin/csh
and not simply

* * * * *
This is because the CRON daemon simply shells the scripts using sh and does not actually fork a seperate shell script process to run the script.

Because I get an error like "sh: ~/spot/startmap.log: cannot create
"

Am I wrong?
4 REPLIES 4
MarkSyder
Honored Contributor

Re: cron error

I've never heard that. I've got several examples of

* * * * *
which work fine.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Robert-Jan Goossens
Honored Contributor

Re: cron error

Elif,

Remember that when something runs from cron, the environment is very sparse. There is little, or no, PATH environment which is the usual cause of problems.

~/spot/startmap.log:

use the full PATH to the log file, cron does not know what user this is, or set the PATH variables in the beginning of your cron script.

Regards,
Robert-Jan
Mancboy
Valued Contributor

Re: cron error

Hi Elif,
cron runs in a basic environment with very little defined.
I always recommend my users run their scripts in a test environment, that has /bin/sh as the shell and litte in the .profile (just as cron will execute the commands).

If you need any environment variables other than the basics ($HOME etc), then run a "setenv" style script that sets up the PATH, ORACLE_SID etc variables.

Also, *ALWAYS* give the full path for all commands in scripts, don't assume that programs such as echo, tar etc will be the correct echos and tars.

I had a user who (when they typed echo) used /usr/bin/echo in their interactive shell, but when they ran their script from cron, it came up with the shell built-in.
And similarly when somebody had several versions of tar in different areas(/opt/bin/tar, /bin/tar). Then gnu tar was added to /usr/local/bin/tar - all of a sudden, the script that called "tar" failed to behave as expected, as /usr/local/bin was first in the PATH.
spex
Honored Contributor

Re: cron error

Elif,

Sorry if I'm stating the obvious, but check that '~/spot/startmap.log' is what you want, and not '~spot/startmap.log'.

As others have said, check that your environmental variables are set up properly. If you're looking to test variables from cron, create a script that echos the variables in question, and read the output. For a more generic approach, you could put environmental variables in a file, and source that file from scripts you run as cron or other users.

PCS