Crond and Environment Variables

Source: Internet
Author: User

Crond and Environment Variables

Problem description:

Write an exp script and place it in oracle's crontab, but it cannot be executed.

Cause

Crond does not load the user's. profile and. bashrc files by default. Its execution environment only has some basic environment variables, so exp commands cannot be executed because they cannot be found.

Verification process

Write a script and grant the 777 permission to [root @ DBBANK ~] # Cat/tmp/wjf/env | wall
Add this script to the scheduled tasks of the root and oracle users respectively.

[root@DBBANK ~]# whoamiroot[root@DBBANK ~]# crontab -l01 * * * * /tmp/wjf/env[root@DBBANK ~]# 
[oracle@DBBANK ~]$ whoamioracle[oracle@DBBANK ~]$ crontab -l02 * * * * /tmp/wjf/env[oracle@DBBANK ~]$ 
The execution result is

Broadcast message from root@DBBANK (Fri May  8 17:36:02 2015):SHELL=/bin/shUSER=rootPATH=/usr/bin:/bin_=/usr/bin/envPWD=/rootHOME=/rootSHLVL=2LOGNAME=root
[oracle@DBBANK ~]$ Broadcast message from oracle@DBBANK (Fri May  8 17:38:01 2015):SHELL=/bin/shUSER=oraclePATH=/usr/bin:/bin_=/usr/bin/envPWD=/home/oracleHOME=/home/oracleSHLVL=2LOGNAME=oracle
You can see the shell environment opened by crond. There are only some of the most basic environment variables, so you should not think about writing the commands in oracle as scripts in oracle's scheduled tasks. Actually, it cannot.

Solution

Manually export the environment variable in the script.

Or

Source environment variable file at the beginning of the script

Or

. (Space) environment variable File


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.