Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com 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

1 Answer 1

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 myscript.py).

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.