/etc/profile and/ETC/BASHRC, interactive and non-interactive, login and non-login shell differences

Source: Internet
Author: User
Tags memcached

the memcached on the line has been hung again, still not getting the core file. For troubleshooting reasons, a colleague discovers that there is a suspicious problem with the script that launches memcached. Issue One: memcached working directory is not set, it is possible that core dump does not have working directory Write permissionThese scripts are started by crontab. The working directory is not set in the script, and this is the crontab of the non-root user. When you start memcached, the working directory is not the directory where the memcached executable file resides. The experiment proves that this is the user's home directory, crontab runs the script to print PWD, the result is "home/work", work is the current user. Issue two: Ulimit-c Unlimited set in/etc/profile is not valid for crontab scripts
after reviewing the relevant data, it is known that the settings in/etc/profile are only valid for the login shell, and the shell environment Crontab run the script is non-login and does not load the/etc/profile settings.
here, you need to summarize the difference between/etc/profile and/ETC/BASHRC, and the interactive and noninteractive, login and non-login shell concepts.
programmers familiar with Linux should have experience setting environment variables in the ~/.profile file, the environment variables set in ~/.profile will only work for that one user, and if they are valid for all users, set/etc/profile. /etc/profile is the global version of ~/.profile. In fact, once an interactive login shell is opened, or a non-interactive shell that is logged on with the--login option, the commands in/etc/profile are loaded and executed first, and then the ~/.bash_profile is loaded sequentially, ~/.bash_ Login, and the commands in ~/.profile.
Here again comes the concept of interactive shell and noninteractive shell,login shell and non-login shell. According to these two dimensions, a total of four shell: Interactive login shell, interactive non-login shell, non-interactive login shell, non-interactive non-login shell.

Interactive : As the name implies, the command in this shell is entered interactively by the user from the keyboard, and the results of the operation can also be output to the terminal display to the user.

non-interactive : This shell may be initiated by some automated process, not directly from the requesting user's input, or directly output the results to the end user to see. The output is best written to a file.

Login : This is a shell that starts when a user is logged into the system by/bin/login and binds to the user. This shell is the first process that a user launches after logging in. When the login process starts the shell, it passes the No. 0 parameter indicating the name of the shell, the first character of which is "-", which indicates that this is a login shell. for bash, for example, the startup parameter is "-bash". When bash starts with the login shell, it executes the commands in/etc/profile, and then/etc/profile calls all the scripts in the/ETC/PROFILE.D directory, and then executes ~/.bash_profile,~/.bash_ The profile calls ~/.BASHRC, and finally ~/.BASHRC calls/ETC/BASHRC.
to identify whether a shell is a login shell, simply execute echo $ under the shell:
# echo
If the output is the shell name, plus a '-' prefix, then the shell is the login shell. such as-bash,-su and so on. Experiment, in my Ubuntu system, open terminal, input echo $, get the "bash", that this is not a login shell. SSH login to the server, execute the same command, get the "-bash" result, the SSH login to the login shell.

Non-login : A shell that does not require login and is started by some programs. The arguments passed to the shell are not prefixed with '-'. In bash, for example, when it is started in a non-login mode, it calls ~/.BASHRC, then calls/ETC/BASHRC in ~/.BASHRC, and finally/ETC/BASHRC calls all scripts in the/ETC/PROFILE.D directory. This interested can open these files and take a look. Non-login shell mainly includes "#su", "#su USERNAME" launched Shell, and graphics terminal (such as Ubuntu terminal), executed scripts and so on. To identify the non-login shell method or execute the #echo $ command, the resulting result without the '-' prefix is non-login.

back to the problem we encountered, the shell of the script launched in Crontab was non-login. Then the commands in/etc/profile are not loaded, so the "ulimit-c Unlimited" command we set up in/etc/profile is not valid for scripts that are started in crontab. As a result, the memcached started in these scripts will not have a core file when they are accidentally hung.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

/etc/profile and/ETC/BASHRC, interactive vs. noninteractive, login and non-login shell differences

Related Article

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.