LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Start up script (https://www.linuxquestions.org/questions/linux-newbie-8/start-up-script-512043/)

mashed 12-19-2006 04:06 PM

Start up script
 
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?

acid_kewpie 12-19-2006 04:13 PM

generally it'd by ~/.bashrc or ~/.profile for a single user or /etc/bashrc or /etc/profile for everyone.

unSpawn 12-19-2006 04:39 PM

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.

mashed 12-20-2006 02:24 PM

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?

acid_kewpie 12-20-2006 03:48 PM

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

mashed 12-23-2006 01:28 AM

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.

acid_kewpie 12-24-2006 09:01 AM

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?

mashed 12-26-2006 01:12 PM

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.)

Tortanick 12-26-2006 01:53 PM

why not post what you want the script to do? Maby there is an alternative to predicting X.

Perhaps you could duplicate you're PAM modual for normal logons, one for KDM/GDM and one for console, then just add you're script to the console one.

I'm not sure what would happen if a user choses console logon from KDM/GDM though

acid_kewpie 12-27-2006 02:09 PM

well what actually is the output from "tty" itself inside and outside of x? unless you have a path issue, i'm pretty confident it will work fine.


All times are GMT -5. The time now is 04:40 PM.