How do I get a script to execute automatically when I log in? Not when the machine starts up, and not for all users, but only when I (or any specific user with the script) login via the GNOME UI.

From reading elsewhere I thought it was .bash_profile in my home directory, but for me it has no effect. When I manually execute it in a terminal window by typing ~/.bash_profile it works, but it won't run automatically when I log in.

I'm running Ubuntu 11.04. The file permission on my .bash_profile is -rwx------. No .bash_profile existed in my home directory before I created it today.

I seem to remember older versions of Linux having a .profile file for each user, but that doesn't work either.

How is it done? Do I need to configure something else to get the .bash_profile to work? Or does the per-user login script need to be in some other file?

.bash_profile, .profile and .bashrc (Which is the one actually used by ubuntu) are loaded each time you open a bash terminal. So actually I'm not sure they will be loaded if you just login into GDM.
–
Juan Sebastian ToteroJun 20 '11 at 0:19

Do you mean when you log in to the GUI, or to the shell?
–
FlimzyJun 20 '11 at 4:03

bash loads them when you start a new shell, so they will only get loaded when you open a terminal window or log into a virtual terminal, not when you log into Gnome (GDM).
–
shiftycowJun 20 '11 at 4:24

I'm using Ubuntu 11.04, as I mentioned in the original question.
–
Mike RowaveJun 20 '11 at 15:06

You know what, I did that before and it didn't work ... except that I didn't write "bash" before the script's path! I'll try it with the bash later. Out of curiosity, when you enter something via the GUI into Startup Applications, in which file is it registered?
–
Mike RowaveJun 20 '11 at 0:40

Startup programs should be registered in /etc/xdg/autostart
–
shiftycowJun 20 '11 at 4:28

Adding bash /home/myusername/scriptname to "Startup Applications" worked! Thanks. However this might be specific to GNOME on Ubuntu, that's why I was wondering about where the entries in that "Startup Applications" menu item are registered, as that would be more likely to be similar in other modern versions of Linux.
–
Mike RowaveJun 20 '11 at 15:05

2

/etc/xdg/autostart appears to be a system-wide file, not specific to a user.
–
Mike RowaveJun 20 '11 at 15:09