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.

2
  • Doesn't mount require root, or at least a root config change to make volumes mountable by non-root users? Mar 1, 2011 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, 2011 at 16:01

4 Answers 4

1

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

4
  • 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, 2010 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 Oct 31, 2010 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 Oct 31, 2010 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? Jul 20, 2012 at 23:08
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.

1
  • 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! Sep 20, 2016 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.

0
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/

You must log in to answer this question.

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