script after login
Hi all,
I want to run a script to make some system variables available for users that login, since when I only have them in my rcS, they are not available after a user logs in. Since I work with embedded Linux, I don have a specific Distro installed, but it is like redhat. I searched the forums and found a solution to change the .bashrc file, but it does't exist in my home directory. So I created a new one, but it's not really working. This is how it is looking like: Code:
#cat .bashrc Code:
export DISPLAY=:0 if I after login manually enter export DISPLAY=:0 my Xserver does work. If it is not entered I get the following error when I want to use my Xserver: Code:
# xclock Code:
# cat rcS Feel free to ask more question is my question was not specific enough, Thanks in advance, Jurrian Dubbeldam |
Assuming it runs through rc/init scripts at bootime, create a script in /etc/init.d and ln -s it in /etc/rc3.d/.
OK, that's not overly indepth but I'm on a time limit, sorry :| |
Quote:
And what do you mean with ln -s in rc3.d? Should I just go to rc3.d (or rc.d) and enter ln -s? Or am I missing something? |
Still can't find a solution to my problem, anyone here that can help me??
|
The .bashrc solution entirely depends on two things:
1.- the shell you use 2.- the way you login 1) bashrc is an init file for bash. If you use another shell (regular sh, csh, ksm, zsh...) then bashrc will not be valid. Check the man page for your shell to get more info about the rc files for that shell. Usually you can find the shell you are running by doing this in command line: Code:
echo $SHELL Code:
man bash |
if I execute the command $SHELL I get the following result:
Code:
# echo $SHELL Code:
Invoked as an interactive login shell, or with --login Code:
# cat /etc/profile Code:
# cat .profile Anyone with a suggestion? Thanx, Jurrian |
The bash startup file ~/.profile is sourced after first attempting either ~/.bash_profile or ~/.bash_login. See INVOCATION in man bash. This is useful to read, because as i92guboj mentioned, which file is source depends on whether the shell is a) interactive, b) a login shell.
You can create a .profile or .bash_profile, but your don't need both. |
I have read the man page, but i guess i am understanding something wrong.
This is how I think it works: I boot my target, which starts linux after the bootloader did it's work. When linux is booted I can login, so I login on root (no other account available yet), and bash starts. So I guess bash is invoked as an interactive login shell. so it would read /etc/profile and ~/.profile, since I don't have ~/bash_login and ~/bash_profile. So I created a file ~/.profile, but it still is not working.. Code from ~/.profile: Code:
# cat ~/.profile Jurrian |
Perhaps the problem is that I run busybox instead of bash??
But when I enter echo $SHELL the reply is /bin/bash. So I guess I have to use bash?? Thanx, Jurrian |
Login as root, and create 4 startup files for root, by running the following commands (caution, they will replace root's startup files):
Code:
echo "echo BASH_PROFILE" >| ~/.bash_profile The SHELL environment indicates your preferred choice of shells to use for applications that spawn a shell, if such applications interrogate $SHELL. It does not indicate what SHELL you must use. |
Note also that order is relevant. Let me explain. If you run on a login interactive mode, bash reads /etc/profile, and after that, it looks for three files:
~/.bash_profile ~/.bash_login ~/.profile In that very same order, and ONLY one is sourced if found: the first one. That means that, if there's a ~/.bash_profile, bash will stop looking, even if that file is empty, so ~/.bash_login and ~/.profile will be ignored. If there's no ~/.bash_profile but there's a ~/.bash_login, it will be read, and ~/.profile will be ignored if it exists. ç About busybox, I never used it as my main shell, and I can't seem to find any real documents about the sh functionality. I'd just use a regular shell like bash. |
Mr. C. This is my output:
Code:
Could you tell me what the >| operator exactly does? I understand that with echo it will be placed in the file name after >|, or is that the only thing the >| operator specifies, in which file it has to be placed? i92guboj, I want to keep my linux as small as possible, so I use busybox instead of a complete bash. Thanx in advance, Jurrian |
Notice your shell :
Code:
BusyBox v1.9.1 (2008-04-11 15:22:42 EDT) built-in shell (ash) The >| operator is redirect with overwrite. |
Since you created the .profile, and upon login you did not see PROFILE, either the .profile was not created in root's home directory, or the ash shell is not a login shell. Look at the output of ps, searching for ash. Does the ash command name in the ps output begin with a dash character (eg. -ash)? This would indicate the ash shell was a login shell, and /etc/profile and $HOME/.profile would be used. Otherwise, they are not. Again, see Invocation.
|
Hi,
At least that makes me feel coming more in the correct direction. After reading the invocation from man ash, I found out it uses /etc/profile or /etc/.profile, and with the ENV variable you can set a path to a new file. So I created a ENV=$HOME/.profile in the /etc/profile, and I exported the DISPLAY variable in ~/.profile. However, still no DISPLAY variable when I echo $DISPLAY... My /etc/profile script: Code:
# cat /etc/profile Code:
Thanx in advance, Jurrian |
All times are GMT -5. The time now is 02:09 AM. |