Init scripts per user

6

2

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.

sasuke

Posted 2010-10-31T09:19:17.850

Reputation: 443

Doesn't mount require root, or at least a root config change to make volumes mountable by non-root users? – Rich Homolka – 2011-03-01T21:11:10.450

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 – 2011-03-12T16:01:52.567

Answers

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

Posted 2010-10-31T09:19:17.850

Reputation: 193

1The 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 – 2010-10-31T14:05:02.070

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 – 2010-10-31T15:01:24.980

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 – 2010-10-31T15:11:21.410

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 – 2012-07-20T23:08:23.720

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'

Posted 2010-10-31T09:19:17.850

Reputation: 58 319

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 – 2016-09-20T15:25:23.297

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

Posted 2010-10-31T09:19:17.850

Reputation: 826

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

Posted 2010-10-31T09:19:17.850

Reputation: 27 121