The UNIX and Linux Forums  

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with script - run by cron richo king Shell Programming and Scripting 2 03-05-2008 08:36 PM
cron ? automating a script hassanj UNIX for Dummies Questions & Answers 8 12-22-2007 09:29 AM
Is it possible to have more than one Cron in shell script? Yamini Thoppen AIX 4 12-17-2007 03:23 AM
Cron job for Perl script man UNIX for Advanced & Expert Users 3 07-26-2007 02:20 PM
Can run script Manually, but not through Cron? MadHatter Shell Programming and Scripting 4 10-19-2005 11:08 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-06-2004
doublek321 doublek321 is offline
Registered User
  
 

Join Date: Jul 2004
Posts: 7
Cron Script Q

When logged in as root if I type "env" there are a bunch of environment settings including one for CLASSPATH. However, I ran a cron script that ran this command "env > cronEnv". I noticed that the environment variables were entirely different inside the script. There wasn't even a CLASSPATH defined. Can any explain to me why that is? It's weird that the user root vs a cron script ran under user root would have different paths. Can anyone explain how to rectify this situation? It's a bash shell in linux by the way.
  #2 (permalink)  
Old 07-06-2004
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,805
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

  #3 (permalink)  
Old 07-06-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
See this thread for an opposing view.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0