We help IT Professionals succeed at work.

Run program on boot

johnslucas asked
Medium Priority
Last Modified: 2013-12-16
I'm using Red Hat Fedora and would like to have a program started under a user account when the computer is booted.

I can log on as a user and enter gedit .bash.rc and add a command to that file.  Unfortunatly this runs each time a terminal window is opened.

Watch Question

In /etc/rc.local add:

su - <user> -c "<command to run>"

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Top Expert 2005
If the command is blocking(runs for vely long time or endlesly), add & at the end
su user -c "command parameters" 2>&1 >/dev/null &


Thanks.  That gets a program running at boot but how do I set path?  I tried both of theses in the /etc/rc.local:  

export PATH=$PATH:/usr/local/pgsql/bin

su username -c "export PATH=$PATH:/.....

and neither worked.
create a shell script to use as the command called by su -c eg

Create an shell script called "/home/<username>/bin/<scriptname>" with this content and make it executable by <username>:

export PATH=$PATH:/usr/local/pgsql/bin
su <username> -c "/home/<username>/bin/<scriptname>" 2>&1 >/dev/null &


Logged on as rrot or user I get "Could not save file /home/<username>/bin/setpath"

Does this file need a particular extension?

How do I make it executable by <username>
Top Expert 2005

unfortunatelly for You su resets the envinronment as default
PATH="/new/path:$PATH" su -m user -c "command parameters" 2>&1 >/dev/null & # where -m stands for preserve env
You can also set the PATH right in the command like:

su - user -c "export PATH=$PATH:/new/path; command parameters" 2>&1 >/dev/null

or set the path in .bashrc or .bash_profile of the user, the - in the su command tells it to set that users environment as usual by running those files just as it does when you log in as that user.

So the preference of the two above depends on if you always want/need the PATH set for the user.  If you only want it set for the program chose the first option.
Q Logged on as rrot or user I get "Could not save file /home/<username>/bin/setpath"
A sorry - I assumed that you would already have a "bin" directory. Run "mkdir ~/bin".

Q Does this file need a particular extension?
A No UNIX/Linux/*X file needs any particular extension

Q How do I make it executable by <username>
A "chmod 700 /home/<username>/bin/setpath"
Since it is Fedora, you should have an /etc/profile.d directory.  Place the script in there and it doesn't matter who logs on.

export PATH=$PATH:/usr/local/pgsql/bin

I usually do one for PATH and another script for ALIAS.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.