Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17
how can i start a linux command as soon as my linux machine (red hat) starts ?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2005
    Posts
    27

    machine starts


    how can i start a linux command as soon as my linux machine (red hat) starts ?

  2. #2
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    Try putting a script in your /etc/rc/rc#.d directory that begins with an S if you want it on system startup, or edit your .xinitrc file to run a program if you want it on X startup.

    Ex.
    Let's say you want script Y to start on system startup on run level 2:

    Add the file S##<name> to /etc/rc/rc2.d
    Edit it to run Y
    <name> can be whatever I'm sure, but the numbers between S and the name, I have no idea what they're supposed to mean (order of execution?) If I'm wrong about this in any way, please correct me; but this is how I got kdm and gdm to not start on my system.

  3. #3
    Linux Guru
    Join Date
    May 2004
    Location
    forums.gentoo.org
    Posts
    1,817
    Quote Originally Posted by Javasnob
    I have no idea what they're supposed to mean (order of execution?)
    Yeah, its order of execution. First all the files that start with "K" since that comes before "S" and then all the others, and in numerical order. In Fedora, there is a file /etc/rc.d/rc.local that is intended for this purpose. It may be in RedHat as well.
    /IMHO
    //got nothin'
    ///this use to look better

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Sep 2005
    Posts
    27
    hi, thank you for the response. i am not a linux expert. so, please bear with me.

    i have made a script "my_script". i want it to run as soon as system starts up.

    question1: but my system has dual boot . windows XP and red hat linux. will there be any problem ?


    you have told

    Let's say you want script Y to start on system startup on run level 2:

    Add the file S##<name> to /etc/rc/rc2.d
    Edit it to run Y
    i dont undestand it. However,i am the root user.


    from your comment i assume,

    step 1 : i should browse into "/etc/rc/" directory.
    step 2: then i should open rc2.d
    step 3: // after that what i should do to run my script "my_script" ?

    please tell me the complete steps.

    Thank you

  6. #5
    Linux Guru
    Join Date
    May 2004
    Location
    forums.gentoo.org
    Posts
    1,817
    You might want to read this article before doing anything, and in particular the section entitled "Adding and removing services".
    /IMHO
    //got nothin'
    ///this use to look better

  7. #6
    Just Joined!
    Join Date
    Sep 2005
    Posts
    27
    hi, i read the article you provided. but it was very difficult. lots of linux commands. and i am


    i have found run level is somewhat like windows priority. right ?


    will you plz tell me the complete steps so that i could run a "hello world" script as soon as system starts up ?

    i am weak in liunx , i confess.

    i am the root.
    i assume the following steps,

    step 1 : i should browse into "/etc/rc/" directory.
    step 2: then i should open rc2.d
    step 3: // after that what i should do to run my script "my_script" ? this script should contain a program which will echo a "hello wolrd" as soon as system starts up.

    will you please tell me the complete steps ?

    if you please tell me the guidelines , i hope i can make it working.

    can you please ?

    thanks for your time.

  8. #7
    Linux User
    Join Date
    Jan 2005
    Location
    Florida
    Posts
    414
    It is inadvisable to log in as the root user as this creates a large security issue, especially if you are unfamiliar with linux.
    You should create a regular user account and use that as your primary login; reserve the root user for times you need to perform system maintenance.
    If you need to perform minor maintenance tasks you need only switch user with the su - command, which gives you root access.

    Once your script is in /etc/rc/rc#.d you don't have to do anything to run it. It should start automatically next time you boot the computer.
    registered linux user: 387197

  9. #8
    Linux Guru Flatline's Avatar
    Join Date
    Feb 2005
    Posts
    2,204
    Are you booting into a graphical interface or just a command line interface? That will make a difference as to where to place your script if you decide on the runlevel method.

    In the RedHat world, the runlevel for booting into a graphical interface is runlevel 5, and the command line bootup is (usually) runlevel 3. If booting into a GUI, you would want to put your script into /etc/rc/rc5.d. If you look at the other files in that directory, you will notice that some start with a K and a number and some start with an S and a number.

    The scripts beginning with a K will not run at boot and the scripts beginning with an S will run at boot; the number indicates the order in which they should run. You will want to rename your script to begin with S and a number that indicates where in the boot script order you want it to run.
    There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence.

    - Jeremy S. Anderson

  10. #9
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    So if you want your sample script "helloworld" to start on console startup (not GUI), and it's located in /usr/bin:

    Code:
    $&#58; su
    Password&#58; <your password here>
    #&#58; cd /etc/rc/rc2.d  <-- I think that's the Fedora directory
    #&#58; touch S99hello
    #&#58; echo "exec /usr/bin/helloworld" > S99hello
    For GUI startup:
    Code:
    $&#58; su
    Password&#58; <your password here>
    #&#58; cd /etc/rc/rc5.d
    #&#58; touch S99hello
    #&#58; echo "exec /usr/bin/helloworld" > S99hello
    Make sure your script is executable, too; I don't know how many times I made that mistake when I first started. I'm also not sure about where the Fedora rc#.d directories are; that's just an edjucated guess.

  11. #10
    Just Joined!
    Join Date
    Sep 2005
    Posts
    27
    Are you booting into a graphical interface or just a command line interface?
    hi, when i boots up (GRUB loader) i get into linux and get a command shell.
    then i type startx to get the GUI. i enter into the GUI this way . i like GUI interface becuase i feel comfortable.


    In the RedHat world, the runlevel for booting into a graphical interface is runlevel 5, and the command line bootup is (usually) runlevel 3. If booting into a GUI, you would want to put your script into /etc/rc/rc5.d.
    i told the above situation about how i boot linux. what do you call it ? run level 3 or run level 5 ?

    should i use
    Code:
    /etc/rc/rc5.d
    OR
    Code:
     /etc/rc/rc3.d
    ?

    The scripts beginning with a K will not run at boot and the scripts beginning with an S will run at boot; the number indicates the order in which they should run. You will want to rename your script to begin with S and a number that indicates where in the boot script order you want it to run.
    excellent !



    It is inadvisable to log in as the root user as this creates a large security issue, especially if you are unfamiliar with linux
    umm......i have a user id as "guest" but i dont use that . because, i want to install script so that every user can use my script . so always i enter as "root" and do the work. becuse i think ,whatever i would do as "root" would be reflected to every user . so i do it as a "root".



    BTW, i am reading this tutorial to run my script

    http://www.linuxcommand.org/wss0010.php#write


    do i really need the PATH settings as they mentioed to run the script as soon as System starts up ?

    i guess NO ...correct ?

    so, i should
    1) write my script
    2) change the permission
    3) copy the script and paste it into dir "/etc/rc/rc5.d"
    4) rename my script name with starting letter "S" .


    are these steps OK ?

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •