Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

/etc/profile variables are not in environment in /usr/bin/ksh called from cron???

Status
Not open for further replies.

ui05067

MIS
Aug 24, 2001
18
US
[sup] Any ideas on how to make the /etc/profile variables availabe to ksh scripts exectued from the cron.
they are availabel when I reference them from the ksh command prompt for the same user that owns the cron.


[/sup]
 
Cron runs is a very minimal environment that has little or nothing to do with the user's own environment. The best strategy I find is to place all important PATH variables etc explicitly in the job being called (or in a 'wrapper' script used by cron to call the job after execution of the environment-setting part). Also, it is best to use /full/path/to/program for things like cp and other commands to avoid any possibility that they will cause problems.

Hoep this helps.

The internet - allowing those who don't know what they're talking about to have their say.
 
Just "dot" the profile you want to use.

Code:
#!/bin/ksh
#
# scriptname   what the script does
#           
#load the default profile from etc
. /etc/profile
# do the script...
 
Sample from one of my cron (oracle):
Code:
30 3 * * 0         (. /home/oracle/.profile; export ORACLE_SID=selrec;. /data/datafiles/backup/rman/scripts/backup_base.ksh tape full) 1>/dev/null 2>&1
It set the profile of Oracle, export a local value, executes the backup (with parameters) and redirects all text to null so oracle don't receive mail.

From matto123, I understand you can 'factorize' the profile at the beginning of the cron, like this:
Code:
. /home/oracle/.profile
30 3 * * 0         (export ORACLE_SID=selrec;. /data/datafiles/backup/rman/scripts/backup_base.ksh tape full) 1>/dev/null 2>&1
Hope that helps.

Christian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top