Book Reviews   Digital Libraries   Astronomy Log   Software   About  
The main stuff

Shell scripting in cron environments
24 August 2005 11:05

I'm going to publicly humble myself here in demonstating my capability to forget that which I've learned once before, for the purpose of hopfully never forgetting it again. I've been writing some backup scripts for Oracle in Bourne shell which dynamically create backup scripts for Oracle Recovery Manager (rman), an then invoke rman, feeding it the backup script that was just created. In testing these scripts I ran into the classic problem of a script which works fine from the command-line but not when invoked from cron. The script would run, but rman would bail with odd, unhelpful errors.

This smelled suspiciously like environment variables not being set so my first course of action was to recognize that not everything in the environment from the command-line will exist in the cron execution environment, so I dutifully set environment variables in my script to provide things like ORACLE_HOME, ORACLE_SID, and PATH:

ORACLE_HOME=/path/to/oracle/product/oravers/
ORACLE_SID=DB_SID
PATH=$PATH:$ORACLE_HOME/bin

But this still didn't fix the problem. The script would run, but rman still behaved like it wasn't seeing the environment set like it wanted. So I looked into another backup script I had written months ago, and found my problem.

You see, the environment variables I set as above were fine for anything that needed to access them within the scope of the current process. The moment I forked off another process, or ran another command (like, say, rman), those environment variables would be invisible to any child processes created by my script. How to resolve this problem? Export the variables:

ORACLE_HOME=/path/to/oracle/product/oravers/; export ORACLE_HOME
ORACLE_SID=DB_SID; export ORACLE_SID
PATH=$PATH:$ORACLE_HOME/bin; export PATH

By doing this, these variables were then visible to any child processes (like rman) that I might run from my script.

Well-seasoned shell scripters will smile at me and say, "well, duh!" In my defense, most of my scripting these days is in Perl, but at any rate, I hope that bloging about this will cement it in my mind enought to remember it 6 or 12 months down the road when I'm writing another similar script.


Comments

On 17 April 2007 05:13 nishant jindal wrote:
i wanna know how to set a oracle database from sybase database and how to set the environment variables

On 04 September 2007 00:32 Amol wrote:
Hi, Thanks a lot for putting up this information. Helped me for scheduling my job correctly in cron.


Add a comment
Your name: (Required)


Your email: (Optional, not displayed)


URL: (Optional, the address of your web site or blog)


Your comments: (Required)

Please enter the text you see in the image
The CAPTCHA image


Thank you!
Please donate
liftingupserenity.com

Some dude

Daniel Hanks

I'm a database/systems administrator working for a large web hosting company in Utah.

Interested in

perl
books
databases
genealogy
astronomy
digital archival
digital libraries
web applications
web infrastructure
distributed storage

among other things . . .

Storyteller


Pamela Hanks

is an excellent storyteller.

(She also happens to be my wife :-)

A storyteller makes a wonderful and unique addition to family, school, church or other group events. Schedule her for your next gathering.


Kiva.org

Recent Entries

Subscribe with Bloglines
- Harnessing human computational power from computer games
- I love a good roadtrip
- FamilySearch Developers Conference 2008 presentations now available online
- FHT follow up: an idea for a mobile genealogical application
- Family history and technology: it's only getting better
- President Hinckley passes away
- December is NaBoMoReMo - National Book of Mormon Reading Month
- Family History, Photos, Blogs, and Books
- The Compact Oxford English Dictionary
- 1830s English and the Book of Mormon
- Google adds My Library feature to Book Search
- Utah Open Source Conference
- Wiki diagrammer (Steal this idea!)
- Microloans at Internet-scale
- Podcasting content created by someone else
- Silver Lining thought: Parking at work
- Emerging technologies for system administrators
- Amazon S3 storage engine for MySQL, part II
- Total lunar eclipse on Sat, Mar 3, 2007
- Are you ready for the 2007 Daylight Savings time changes?

All Entries . . .

LDSOSS
LDS Open Source Software
A website discussing the use of Open-source software for applications useful to those sharing values of the Latter-day Saint (Mormon) faith.

Cool Perl Modules

My del.icio.us
Recent bookmarks

Spread the Word
Get Firefox!

--> © 2004, Daniel C. Hanks