• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

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
0
johnslucas
Asked:
johnslucas
  • 2
  • 2
  • 2
  • +2
5 Solutions
 
sheetbirdCommented:
In /etc/rc.local add:

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

0
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now