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.

There is a script (more like a command) which I would like to be executed on a per user-login basis. I've heard of init.d scripts but those require root permissions and are not per-user customizable (AFAIK). Simply put, I am looking for something along the lines of .bashrc which would be executed only once per user login.

To detail a bit about the scenario, I currently use a Ubuntu guest OS on a Windows host (emulation courtesy of VirtualBox). Every time I login to my guest OS, I need a mount command to be executed which would mount my shared folders to a common directory in the user's home directory.

share|improve this question
    
Doesn't mount require root, or at least a root config change to make volumes mountable by non-root users? –  Rich Homolka Mar 1 '11 at 21:11
1  
@Rich: Indeed it does; I don't mind seeing a password prompt when I fire up my shell. It's just that the mount command is pretty complicated and I didn't want to put in extra effort of executing a helper script. –  sasuke Mar 12 '11 at 16:01

4 Answers 4

up vote 1 down vote accepted

you can try the different options here: http://library.gnome.org/admin/gdm/stable/configuration.html.en , you probably want the PostLogin option

share|improve this answer
1  
The problem here is that all of those options require a change in the /etc/* files which require root privileges. Isn't there any file I can create/edit to ensure that a script is executed only when I login to the system? Something like .bashrc which is invoked on every bash session and is private to the user? –  sasuke Oct 31 '10 at 14:05
    
ok, I missed the root rights, obviously. You can try writing a .xinitrc or a .xsession file: acm.uiuc.edu/workshops/cool_unix/xinitrc.html –  natxo asenjo Oct 31 '10 at 15:01
    
no, that won work either. What will work is to add your script to the startup applications (provided ubuntu has such a thing). In fedora you get there from system -> preferences -> starup applications. Here there is a ubuntu link: help.ubuntu.com/community/AddingProgramToSessionStartup –  natxo asenjo Oct 31 '10 at 15:11
    
That does it I guess, thanks. –  sasuke Oct 31 '10 at 16:59
    
I think it's strange that there isn't a standard for this in Linux. Everyone needs a different method according to the distribution? Or perhaps there is a standard? –  kilaka Jul 20 '12 at 23:08

Maybe I didn't grasp all the subtleties, but I think that you can do that if you are using ubuntu, I guess that you could just write a script for each user (or a script with different rules depending on 'whoami') and, if they are using gnome (as it's default for Ubuntu), add that script to startup applications.

share|improve this answer
    
+1 this method will work in ubuntu –  natxo asenjo Oct 31 '10 at 15:23

Linux cron (written by Paul Vixie, so called Vixie cron) has the meta keyword @reboot, which will start things as the crontab owner upon reboot. See http://www.cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot/

share|improve this answer

The standard place for commands to run when you log in is ~/.profile. There are some environments where this file is skipped when you log in directly in graphics mode, but with Ubuntu 10.04, ~/.profile is read by gdm, kdm, lxdm and xdm login scripts (in addition to when you log in on a text console or over ssh).

If you have a ~/.bash_profile, your ~/.profile will sometimes be skipped. It is best to put only the following two lines in your ~/.bash_profile:

. ~/.profile
. ~/.bashrc

Then put login-time actions in ~/.profile and shell customizations in ~/.bashrc.

share|improve this answer

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.