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?
Running Script as Another User. By default, the su command takes an input a target username to switch into. However, we can specify a script to be run with the flag -c. When specified, su command will just execute the script without dropping into a new shell as the target user.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With