Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
How can I create a script that runs after a certain user has logged in? If I I'm running an x-server I can obiously use .xsession, but what if I'm not running an x-server?
create a script that runs after a certain user has logged in
Since this question isn't that clear to me, one word of caution. It depends if you vant to run ze script that is under ze control of a user or if it's for system-wide purposes. In ze first case (say you vant to start say ssh-agent) ~/.bash_login will do. In ze second case you will vant to resort to something outside of the users control for which you can use PAM modules like PAM_script.
Script that is that is under the control of a user will do, like the one you get by editing .bashrc. However, how do you write a script that is run only if x-server is not running on the display that has logged in?
ok if that's the route you wish to go down, you just need to do something like checking the output of the "tty" command with your bash script. if it starts "/dev/tty" then your in a real console, if not, and it's /dev/pts/1 or something then you're in a terminal within an x session:
(tty | grep tty > /dev/null) && command to run when in real terminal || command to run when in emulated terminal
Hmm. still didn't quite work. I'm trying to write a script that is run only if login is not going to start the x-server. (tty | grep tty > /dev/null) shows tty in both cases, so the script is run always. (Because, if the x is goint to be started it is not already on.) I think, that the only time (tty | grep tty > /dev/null) doesn't result tty is, when you are in an emulated console.
oh, so it's whether x is going to be started, not whether it's alread been started? well what are you actually referring to with regards to when the x server will or won't start? runlevel?
When you are running the x-server, it usually runs on emulated console #7, I want to create script, that is not run, if you log in trough emulated console #7 while in runlevel 5. (And, in another words, this means that script is always run, if you don't use an x serve. Because that means, that you are not loggin in trough console #7 at rl 5).
For some reason, the "(tty | grep tty > /dev/null) && command" is run, when I log in at #7 in rl 5, even though the x is supposed to be running (So maybe it is reset at some point in login process? I don't know.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.