6

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.

Gaff
  • 18,569
  • 15
  • 57
  • 68
sasuke
  • 453
  • 1
  • 5
  • 11
  • Doesn't `mount` require root, or at least a root config change to make volumes mountable by non-root users? – Rich Homolka Mar 01 '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 Answers4

5

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.

Gilles 'SO- stop being evil'
  • 69,786
  • 21
  • 137
  • 178
  • You've resolved a 2-day journey as to why .bashrc and .profile were being ignored at login. The other admin made a .bash_profile at one time -- after erasing it and relogging, everything worked wonderfully again! Woot! – Dooley_labs Sep 20 '16 at 15:25
1

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.

celebdor
  • 936
  • 5
  • 7
1

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

natxo asenjo
  • 193
  • 5
  • 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: http://www.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: https://help.ubuntu.com/community/AddingProgramToSessionStartup – natxo asenjo Oct 31 '10 at 15:11
  • 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? – AlikElzin-kilaka Jul 20 '12 at 23:08
1

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/

Rich Homolka
  • 31,057
  • 6
  • 55
  • 80