8

I have some commends that I wish to be called right after login, including 'startx', and I thought rc.local seems a nice place for them, but the problem is that rc.local is run as root and I don't want that, obviously I can do something like this:

su username -c somecommend-here

But I am looking for a way to run the whole 'rc.local' as normal user, or perhaps there is a better place to put my code ?

PS. I am using Ubuntu-mini-remix 1104i386

Thanks

omeid
  • 339
  • AFAIK rc.local is executed parallel to login at the end of the boot sequence. I mean, it will be executed even if you don't log in, but you can be logged in ant it could be pending execution. – Javier Rivera Oct 07 '11 at 06:57
  • @JavierRivera So what would be the solution ? – omeid Oct 08 '11 at 12:15

3 Answers3

6

The easiest way to launch a command when a user logs in is to create a .desktop file for the command and stick it in the ~/.config/autostart folder. What does the desktop file look like? Here is an example that retrieves the Ask Ubuntu home page with wget every time the user logs in:

[Desktop Entry] 
Name=Launch wget
Comment=Fetches the Ask Ubuntu home page.
Exec=wget http://askubuntu.com/
Nathan Osman
  • 32,155
1

I don't know the differences between /etc/rc.local and a crontab, but I generally make a service account and add the appropriate job. For example: sudo crontab -u p4padmin -e

@reboot ~/bin/p4p -d -r ~/var/p4p/cache/foo -p 2020 -t depot:2020 -L ~/var/p4p/log/foo.log

You don't have to login for the service to execute.

0

The linux way is to append your commands to ~/.bashrc instead of /etc/rc.local.

Every user has a .bashrc in it's home directory. This scriptfile is run automatically just after a user logs in. It is run with the credentials of the user so a su command is not needed.

It seems to me that this is exactly what you are looking for.

Eric Carvalho
  • 54,385
thom
  • 7,542
  • This is not quite correct, as .bashrc is not read when a user logs in using the normal lightdm, for example. –  Mar 03 '13 at 18:32
  • I concluded too fast that the user was using a commandline login instead of a display manager because of the "manual" startx command he mentioned....my bad :-) – thom Mar 03 '13 at 23:20