CentOS environment variable settings
~ /. Bash_profile &&~ /. Bashrc
"/Etc/profile ","~ /. Bash_profile "and other configuration files will be automatically executed.
The execution process is as follows:
- When logging on to Linux, first start "/etc/profile ",
- Then start "~ /. Bash_profile ",
- If "~ /. Bash_login "and "~ The/. profile file is also executed when it exists.
Next let's take a look "~ /. What is in the bash_profile file?
$cat ~/.bash_profile# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then . ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/bin:/home/work/local/python/lib/python2.6/site-packages/django/bin/:$HOME/bin:/home/work/local/mysql5/bin/;LD_LIBRARY_PATH=/home/work/local/mysql5/lib/mysqlalias py='/home/work/local/python/bin/python'export PATH LD_LIBRARY_PATHunset USERNAME
You can see ~ /. Bash_profile file is called first ~ /. Bashrc, and then load PATH and LD_LIBRARY_PATH.
Environment variable configuration file
- /Etc/profile: This file sets environment information for each user of the system.When you log on for the first time, the file is executed and shell settings are collected from the setting file in the/etc/profile. d directory.
- /Etc/bashrc:Every user running bash shell executes this file. When bash shell is opened, this file is read.
- ~ /. Bash_profile: each user can use this file to input the shell information dedicated to his/her use. When a user logs on, this file is executed only once. By default, it sets some environment variables to execute the user's. bashrc file.
- ~ /. Bashrc: This file contains bash information dedicated to your bash shell. This file is read when you log on and every time you open a new shell.
- ~ /. Bash_logout: execute this file every time you exit the system (exit bash shell.
/Etc/profile is a global function, in which the set variables act on all users ,~ The variables set in/. bash_profile can inherit the variables in/etc/profile and act on users.
- ~ /. Bash_profile is interactive and login to run in bash.
- ~ /. Bashrc runs in bash in interactive non-login mode.
Generally, the two settings are roughly the same, so the former usually calls the latter.
Crontab execution environmentAs we all know, crontab is a good job. It can regularly execute some tasks to help you monitor system conditions and help you repeat mechanical tasks every day. However, crontab has a bad problem, that is, it does not read environment variable parameters from the user profile file by default, which often leads to a successful execution of a script by hand, however, an error occurs when the crontab attempts to periodically execute the program.
Generally, crontab cannot run because environment variables are not necessarily identifiable in crontab.
When running crontab, the program is called in the non_login method ~ /. Bash_profile is not called in advance. Therefore, the running environment of crontab is much smaller than the running environment of bash in the login mode. If the program involves ~ /. Bash_profile: The environment variables used, so some programs that can run normally in the login mode cannot run under crontab.
Ultimate recommended solution:
30 12 * * * source ~/.bashrc && cd /home/work/mydir && ./myproj