I have a script which I want to run just after user log-in authentication. To accomplish this, I added the script name in /etc/rc5.d/S##rc.local file. But later i got to know that, anything that is added in rc.local file gets executed in boot time of the system not after the login authentication. Can anyone tell me how to run the script after user login authentication?
-
1Are you doing this for convenience or for security? I.e. do you just want to set up your login environment (add aliases, set variables, etc), or do you want your script to run after each login without allowing users to remove it?lanzz– lanzz2012-05-29 10:20:48 +00:00Commented May 29, 2012 at 10:20
-
For the security purpose. Actually i want to run the script whenever admin log-in the system.user976754– user9767542012-05-29 10:23:39 +00:00Commented May 29, 2012 at 10:23
-
2if any of the answers below helped you, please mark them as accepted. thanks.scrat.squirrel– scrat.squirrel2012-10-16 20:29:51 +00:00Commented Oct 16, 2012 at 20:29
3 Answers
For bash:
You can add your script to /etc/profile.d folder.
More reading about this here and here.
Basically, you should give your script the extension .sh as all these files are executed in a loop after user logs on.
6 Comments
Try adding this to your /etc/pam.d/login:
session optional pam_exec.so /bin/bash /path/to/your/script.sh
You will need to check in your script if the current user is actually an administrator (according to whatever your criteria for being administrator are).
5 Comments
pam_exec apparently does not display its output on the terminal where the user is logged on. Do you need to display anything in your script, or just to perform something in the background (e.g. send a notification)? You can add a log file where your script's output will be logged: session optional pam_exec.so log=/path/to/logfile /bin/bash /path/to/your/script.sh/etc/pam.d/login. I think it's the reason why uname gets printed when I ssh to a machiine : session optional pam_exec.so type=open_session stdout /bin/uname -snrvm/etc/pam.d/common-auth instead of loginFor Linux Mint and Ubuntu with Desktop environment there is a option in main menu called "Startup Applications", just go there and add the path to the script file. This script will run after login in window manager.