Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am fairly new to Linux and am quite new to Gentoo. A month ago, I was using Ubuntu, but I wanted more control of my system. I switched to Debain and then again wanted a more custom kernel... I decided to use Gentoo.
Anyway, I want to execute a shell script when <user1> (and only <user1>) logs on. I am assuming there's either a place to place such a file or an already existing "dot" file. I just don't know about it and haven't been able to find an answer searching Google.
If nothing else, I am willing to use 'whoami' to determine if the logged on user is <user1>, but I still don't know where to place such a file.
"When Bash is invoked as an interactive login shell, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable."
@fylnq: so add something like: "exec ~/script_name.sh &" to ~/.bash_login?
That would replace the shell with ~/script_name.sh. If that's what you want to do it can be done by configuring the user's entry in /etc/passwd with <full path to>/script_name.sh
Note that the user is free to change his shell of choice, rendering this useless. Note as well that the user is perfectly free to edit bashrc as you did, with similar results.
There's nothing wrong in this solution, just bear in mind that it won't work in situations where you don't trust the user.
In such situations you would need to look at the authentication system, usually pam.
There's nothing wrong in this solution, just bear in mind that it won't work in situations where you don't trust the user.
In such situations you would need to look at the authentication system, usually pam.
Or make user-specific changes in a file the user can't change -- /etc/profile or something it sources (messy -- there should (TM) be nothing user-specific in a global file).
@i92guboj - yes, the idea is not to change the shell the user uses. Instead, just run a process on logon.
I don't think you understood the point of my post.
~/.bash_login and ~/.bashrc are files that are sourced by bash (and by no other shell). Any given user can use the "chsh" command to change his/her login shell (to sh, zsh, ksh, csh or whatever other shell s/he wants). If a given user does that, then the contents of the bash initialization files will never be parsed, and hence your code will never be run.
If you meant that you know beforehand that the user is never going to do that then it's fine.
@i92guboj - the aforementioned user (<user1>) is my girlfriend (a Windows users). I refuse to dual-boot windows on either of my computers but she doesn't like using FluxBox, and can hardly remember how to login. She's not going to attempt to change shells -- the script that is executed when she logs on just starts X and XFCE4, so she doesn't have to 'startx'. Like I said in my original post, I just needed to execute a shell script when the user logs on (via bash).
Thank you all for your input. And i92guboj, sorry if I was too vague in my original post(s).
Not vague, I couldn't know it was your girlfriend, and I didn't know how skilled that other user was going to be. I was just warning you about the hole in that method in case it was an issue for you. If it's not then you have one less thing to worry about, and you can just ignore that information for the time being.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.