Feb 3, 2011

How to run a shell script after login

You can run every shell script you like if you put it into the /etc/profile file.

After login most linux systems run the /etc/profile script. (many others too, but this one would do it)

If you want a script to run for a single user only, you can use the .profile file in users home directory
(/home/username/.profile)

If your script is called afterlogin.sh and located at /opt/afterlogin.sh you just need to add:
bash /opt/afterlogin.sh or /opt/afterlogin.sh (if execute bit is set! chmod +x /opt/afterlogin.sh)
to your /etc/profile or /home/username/.profile file.

After login your script will execute now.

No comments:

Post a Comment