1826614 Members
2648 Online
109695 Solutions
New Discussion

Cron help...

 
SOLVED
Go to solution
Hazem Mahmoud_3
Respected Contributor

Cron help...

Ok, I am somewhat perplexed about what I'm doing wrong. Here is a script:
-rwxr-xr-x 1 speclive live 694 Jan 15 10:01 apostdat

All it basically does is update a number in this file:

-rw-rw-r-- 1 speclive live 15 Jan 15 00:32 DPOSTDAT

When I run apostdat script, as root FROM THE COMMAND LINE it works fine and updates DPOSTDAT.
When I add the following entry in cron (through "crontab -e"):

03 10 * * * /var/summit/spectrum/FI1/FI/DATA/apostdat

It doesn't update the file. What is going on here?! /var/adm/cron/cron.allow file includes root.
Does it have to do with the permissions of either the script or the file the script is updating? But I am able to run it successfully as root, so why not through cron as well?
Thanks and the right answer will be fully rewarded:)

-Hazem
5 REPLIES 5
Jean-Luc Oudart
Honored Contributor
Solution

Re: Cron help...

Hazem,

the pb might be you must initialize your PATH (and other variables) within your script.
(cron does not run the profile)

The other way around is to have a wrapper script that will initialize all required variables before yu run the specific script.

Rgds,
Jean-Luc
fiat lux
Tom Danzig
Honored Contributor

Re: Cron help...

Keep in mind that commands run from cron do NOT import the environment settings from /etc/profile and ~/.profile (they are not sourced). Most likely this is theissue. Use a PATH= statement in the script to set the path and any other vars that need to be set. Or have the script soure /etc/profile, etc.

cron should mail back a message to the user with any errors (i.e. command not found) encountered.

Marco Santerre
Honored Contributor

Re: Cron help...

is your PATH defined in your shell script? If not, then you ought to define as cron doesn't import your environment profiles.
Cooperation is doing with a smile what you have to do anyhow.
Pete Randall
Outstanding Contributor

Re: Cron help...

Hazem,

In a word: alway use full path names in scripts. You can also set paths within the script but it's just as easy to use the full path name.


Pete

Pete
Hazem Mahmoud_3
Respected Contributor

Re: Cron help...

You guys are awesome! Thanks! I did not include the full path name of a script running inside there that actually does the editing of the file (qedit). Once I added the full path, it worked great!!! I figure it's better to add the full path as opposed to setting the PATH variable for security reasons. But that just completely slipped my mind. Thanks again you guys!
This forum is great!

-Hazem