The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: Cron Script Q
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 07-06-2004
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,729
cron makes an internal system call to create a process and start the script. The system call is execv - it "loses" environment variables. This is a very common problem for folks trying to use cron.

If you need environment variables, have cron call a script that sets up what it needs when it starts to run. When you login, if you don't run .profile, .bashrc, .cshrc, or /etc/profile you have no environment to speak of. cron jobs do not execute all of these login scripts by default, so they are like a user that doesn't 'login correctly' in that sense.

try starting your script with stuff like this, which is just an example, not a template:
Code:
#!/bin/ksh
. /etc/profile
. /path/to/.profile  
# do your stuff here