Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the environment variable of crontab

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "the use of crontab environment variables", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "the use of crontab environment variables" bar!

Environment: (product, platform, model, software version, etc.) AIX5L

Problem description: the shell script started in crontab does not work properly, but there is no problem with manual execution, and the environment variables required for the script are set in $home/.profile.

Answer: the default shell for the cron command is / usr/bin/bsh, and if you want to use ksh in a script started by cron, you must add a declaration of "#! / usr/bin/ksh" on the first line of the script.

If the shell script started by the cron process wants to use the environment variables at login, you must add the following to the shell script started by cron before you can use it in the started script

The environment variable in the $home/.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 itself is required to load the required environment variables.

=

Environment variable file loading order

/ etc/profile: this file sets environment information for each user of the system and is executed when the user logs in for the first time.

And collect shell settings from the configuration file in the / etc/profile.d directory.

/ etc/bashrc: execute this file for each user running bash shell. When bash shell is opened, the file is read.

~ / .bash_profile: each user can use this file to enter shell information dedicated to their own use. When the user logs in, the file is executed only once! By default, he sets some environment variables and executes the user's .bashrc file.

~ / .bashrc: this file contains bash information specific to your bash shell, which is read when you log in and each time you open a new shell.

~ / .bash_logout: execute this file every time you exit the system (exit bash shell).

In addition, the variables (global) set in / etc/profile can act on any user, while the variables (local) set in ~ / .bashrc and so on can only inherit the variables in / etc/profile, they are "father-son" relationship.

~ / .bash_profile is interactive and login enters bash to run.

~ / .bashrc is entered into bash by interactive non-login.

Usually the two settings are roughly the same, so the former usually calls the latter

Thank you for your reading, the above is the content of "the use of environmental variables of crontab". After the study of this article, I believe you have a deeper understanding of the use of environmental variables of crontab, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report