/Etc/profile and/etc/bashrc, interactive and non-interactive, the difference between login and non-login shell, bashrcnon-login

Source: Internet
Author: User

/Etc/profile and/etc/bashrc, interactive and non-interactive, the difference between login and non-login shell, bashrcnon-login
The online memcached crashes again and still does not get the core file. Check the cause and find that the script for starting memcached has a suspicious problem. Problem 1: The memcached working directory is not set. It is possible that the script is started by crontab when the core dump has no permission to write to the working directory. The script does not set a working directory, which is a non-root crontab. When memcached is started, the working directory is not the directory where the memcached executable file is located. The experiment proves that this is the user's home directory. The script running crontab prints pwd and the result is "home/work", and work is the current user. Problem 2: The crontab script of ulimit-c unlimited set in/etc/profile is invalid.
After reading the relevant information, we know that the setting in/etc/profile takes effect only for Login Shell, while the shell environment where crontab runs the script is non-login, the setting of/etc/profile is not loaded.
Here, we need to summarize the differences between/etc/profile and/etc/bashrc and the concepts of interactive and non-interactive login and non-login shell.
Programmers familiar with Linux should have been ~ /. Experience in setting environment variables in the profile file ~ /. The environment variables set by profile are only valid for that user. To be valid for all users, set/etc/profile. /Etc/profile is ~ The global version of/. profile. In fact, once you open an interactive login shell or use the -- login option to log on to a non-interactive shell, the commands in/etc/profile are loaded and loaded in sequence ~ /. Bash_profile ,~ /. Bash_login, and ~ /. Profile command.
The concepts of Interactive shell and non-interactive shell, login shell and non-login shell are involved here. There are four types of shells: Interactive login shell, interactive non-login shell, non-interactive login shell, and non-interactive non-login shell.

Interactive: As the name suggests, commands in this shell are input interactively by the user from the keyboard, and the running results can also be output to the terminal for display to the user.

Non-interactive: This shell may be started by some automated processes and cannot be directly input from the requesting user or output to the end user. It is best to write the output to a file.

Login: This is the shell started after a user logs in to the system by/bin/login. It is bound to this user. This shell is the first process started after the user logs on. When the login process starts the shell, it passes 0th parameters to specify the shell Name. the first character of this parameter is "-", indicating that this is a login shell. For example, for bash, the startup parameter is "-bash ". When bash is started with a login shell, it will execute the command in/etc/profile, and then call all the scripts in the/etc/profile. d directory. Then execute ~ /. Bash_profile ,~ /. Bash_profile call ~ /. Bashrc, last ~ /. Bashrc calls/etc/bashrc again.
To identify whether a shell is a login shell, run echo $0 in the shell:
# Echo $0
If the output is the shell name with a '-' prefix, it indicates that the shell is a login shell. For example,-bash and-su. In my Ubuntu system, open Terminal and input echo $0 to get "bash". This is not a login shell. Log on to the server via SSH and run the same command. The result of "-bash" is displayed, indicating that the log on via SSH is login shell.

Non-login: The shell started by some programs without login. The parameters passed to the shell do not have the '-' prefix. Bash is also used as an example. When started in non-login mode, it calls ~ /. Bashrc, and then ~ /. Bashrc calls/etc/bashrc, and finally/etc/bashrc calls all scripts in the/etc/profile. d directory. If you are interested, open these files and have a look. Non-login shells mainly include shells started with "# su", "# su USERNAME", graphical terminals (such as Terminal of Ubuntu), and executed scripts. To identify non-login shell methods, run the # echo $0 command. If the obtained result does not have the '-' prefix, it is non-login.

Back to the problem we encountered, the shell scripts started in crontab are non-login. The command in/etc/profile will not be loaded, so the "ulimit-c unlimited" command we set in/etc/profile is invalid for the script started in crontab, therefore, the memcached started in these scripts will not have core files after being plug-in.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.