Run program on boot

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.

Thanks
John
johnslucasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sheetbirdCommented:
In /etc/rc.local add:

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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ravenplCommented:
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 &
0
johnslucasAuthor Commented:
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.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

sjm_eeCommented:
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>:

#/bin/bash
export PATH=$PATH:/usr/local/pgsql/bin
su <username> -c "/home/<username>/bin/<scriptname>" 2>&1 >/dev/null &
0
johnslucasAuthor Commented:
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>
0
ravenplCommented:
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
0
sheetbirdCommented:
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.
0
sjm_eeCommented:
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"
0
sr75Commented:
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.

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


I usually do one for PATH and another script for ALIAS.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.