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

2
  • 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. Oct 7, 2011 at 6:57
  • @JavierRivera So what would be the solution ?
    – omeid
    Oct 8, 2011 at 12:15

3 Answers 3

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/
3
  • Does not seem a good idea to launch startx (as the OP asked) after graphical login.
    – enzotib
    Oct 7, 2011 at 7:46
  • @enzotib: There is no mention of a graphical login. Oct 7, 2011 at 16:27
  • Maybe I misunderstood the question, I believed the user would to start startx from rc.local. Sorry
    – enzotib
    Oct 7, 2011 at 16:38
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.

2
  • This is not quite correct, as .bashrc is not read when a user logs in using the normal lightdm, for example.
    – user76204
    Mar 3, 2013 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 3, 2013 at 23:20

You must log in to answer this question.

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