Use environment variables in crontab: (products, platforms, models, software versions, etc.) AIX5L www.2cto.com Problem description: shell scripts started in crontab cannot run normally, but there is no problem when using manual execution. In $ home /. profile sets the environment variables required by the script. A: The default shell of the cron command is/usr/bin/bsh. To use ksh in the script started by cron, you must add "#! /Usr/bin/ksh "statement. If the shell script started by the cron process uses the environment variable at logon, you must add the following content to the shell script started by cron to use $ home /. environment variables in the profile file. . $ Home/. profile this is because the shell script executed by the cron process does not automatically load the. profile file in the user directory, so the script needs to load the required environment variables by itself. =================== Environment variable file loading sequence/etc/profile: This file sets environment information for each user of the system, this file is executed when the user logs on for the first time. and from/etc/profile. the configuration file in the d directory Collects shell settings.
/Etc/bashrc: execute this file for every user running bash shell. When bash shell is opened, this file is read .~ /. Bash_profile: each user can use this file to input the shell information dedicated to their own use. When a user logs on, this file is only executed 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). In addition, the variable (global) set in/etc/profile can act on any user, and ~ The variables (local) set in/. bashrc and so on can only inherit the variables in/etc/profile. They are "Parent-Child" relationships .~ /. Bash_profile is interactive and login to run bash ~ /. Bashrc is the interactive non-login mode that enters bash. Generally, the two settings are roughly the same, so the former usually calls the latter.