Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a feeling this is quite easy to do but every solution found on google has to do with adding a script to be run whenever someone logs into the machine.

What I am looking for is a way to run a script when only I log into the machine. I ssh into a shared computer and need to have it load a couple modules for me and I imagined the easiest way to do this would to just run a script on login. Is there a simple way?

share|improve this question

migrated from Sep 4 '12 at 1:15

This question came from our site for professional and enthusiast programmers.

Do you want to stay logged into an interactive session? Or have it also automatically disconnect after the script is run? – Keith Sep 3 '12 at 20:38
up vote 2 down vote accepted

Adding it to your users .bashrc file in /home/USER/.bashrc should do the trick. If the script is in bash, just add the code to the file directly. If it is not bash, (python, perl, whatever), call it from your bashrc as you would from the command line (python

Here is an example bashrc file.

share|improve this answer
Perfect adding it to the .bashrc is exactly what I was looking for. – user912447 Sep 3 '12 at 21:06
You might want to add it to .bash_profile instead. Depending on how you use the machine, you may start other non-login interactive shells, which would also execute your .bashrc file. (True, it's possible to start additional login shells once you are logged in, so really this is just FYI in case you ever observe your "login" script being executed again after you've logged in.) – chepner Sep 3 '12 at 21:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .