I want to execute a certain bash script when a certain user logs in.
I thought of calling the script in the initialization file of that user e.g. .bashrc, but this is not applicable, as in real life others shouldn’t be allowed to write in users initialization files.
How can I do this?
I want to execute a certain bash script when a certain user logs in.
Share
I could solve it using the comman
fingerin an infinite loop and when the lines output of the command increase that means that someone logged in and then I can handle that by doing whatever I want with this user, here is the code:Note: you can initialize
nwithn=${finger | awk 'END{print NR}'}to avoid considering that someone logged in at the beginning of script execution,or whatever you want.