Results 1 to 6 of 6
Hi,
There is a script that I want to run as root when the machine boots up(which starts the Redhat Certificate System services). The problem I have is if I ...
- 04-29-2009 #1Just Joined!
- Join Date
- Jan 2008
- Posts
- 9
Running a script as root on system startup
Hi,
There is a script that I want to run as root when the machine boots up(which starts the Redhat Certificate System services). The problem I have is if I put this on rc.local it wont run because I havent logged in as root. Is there a way that I can run this without logging in as root at the machine startup?
Putting this on root's .bash_profile is not a solution for me.
Thanks...
- 04-29-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
What run-level do you want your script to execute at? The valid bootup run-levels are 1 (single user mode), 2 (multi-user - no network), 3 (full multi-user), and 5 (multi-user w/ X11). Put your script in /etc/rc.d/rcN.d, where 'N' is the run-level. The system initialization script rc will automatically execute the scripts that it finds there when the runlevel changes. You probably want to put it in rc3.d, but you can also add a call to your script in rc.local. That will get executed after all the other init scripts called by rc and rc.sysinit are run.
FYI, there are also run-levels for shutting down (1) and rebooting the system (6), but that isn't what you indicated you need to do; however if you need to do some cleanup when the system is shut down, then adding a script to rc1.d and rc6.d is the way to do that.Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 04-30-2009 #3Just Joined!
- Join Date
- Jan 2008
- Posts
- 9
Hi,
I need to run this on runlevel 5. Putting the script on /etc/rc.d/rc5.d did not worked. The script that I want to run contains the following message,
# This script must be run as root!
So as I think because I am not logged in as root when the scripts at /etc/rc.d/rc5.d are executed, the script that I want to run is not getting executed. I want to find out a way so that i can execute that script without logging in as root. I tried putting sudo <myscript> on rc.local after setting the NOPASSWD option by editing /etc/sudoers but it also didnt worked. Any help on this is highly appreciated.
Thanks...
- 04-30-2009 #4
chage the ownership and groupto root. if you have selinux on set the selinux context too.
- 04-30-2009 #5Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
You aren't logged in at all when these scripts execute. They are executed by the system, but must be owned by root and have the appropriate permissions set. See the previous posting by rituraj.goswami for details.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 05-01-2009 #6Just Joined!
- Join Date
- Apr 2009
- Posts
- 17
rc.local ?have you tried that ?


Reply With Quote
