How to automatically execute a script at start-up ?


Results 1 to 6 of 6

Thread: How to automatically execute a script at start-up ?

  1. #1
    Join Date
    May 2003
    Location
    San Jose
    Posts
    37

    How to automatically execute a script at start-up ?

    Hello, I was wondering is someone could help me find out how to execute a specific script at startup every time my computer boots up. I would prefer to execute it as root, but as long as it works. I want it to do the following :

    su server1
    cd /home/server1/hlds_l
    screen -A -m -d -S mypub ./hlds_run -game cstrike +ip ****** +map de_dust +maxplayers 20 -pingboost 1
    exit
    su server2
    cd /home/server2/hlds_l
    screen -A -m -d -S mypriv./hlds_run -game cstrike +ip ****** +map de_dust -pingboost 1 +maxplayers 12
    exit



    that is all I want it to do. Any help would be greatly appreciated. Thanks.

  2. #2
    Join Date
    Mar 2003
    Location
    Here
    Posts
    343
    Well, to make it neater, create that as a seperate script somewhere (if you have no idea, go /usr/local/bin/myscriptnamehere or something), chmod +x filename it, and then add it to the startup script:

    For Redhat, maybe Mandrake (not sure, haven't used it):

    edit: /etc/rc.d/rc.local
    or /etc/rc.local

    (usually symlinked together.)

    Put the line

    /usr/local/bin/myscriptnamehere &

    at the end of the file. It'll run as root whenever you boot up.


    If you use another distro, post the name here and I'll help. (Or try to.)
    If you're running into difficulties find rc.local, look around for a S99* file in /etc/init.d

    Hope that helps,

    Robbo
    "Heisenberg may have been here."

  3. #3
    Join Date
    May 2003
    Location
    San Jose
    Posts
    37
    Sorry i found it, too late in the night for me =( anyway here is the file content :

    Code:
    #!/bin/sh
    #
    # This script will be executed *after* all the other init scripts.
    # You can put your own initialization stuff in here if you don't
    # want to do the full Sys V style init stuff.
    
    [ -f /etc/sysconfig/msec ] && source /etc/sysconfig/msec
    [ -z "$SECURE_LEVEL" ] && SECURE_LEVEL=3
    
    # Source functions
    . /etc/init.d/functions
    
    if [ -f /etc/mandrake-release -a $SECURE_LEVEL -lt 4 ]; then
        R=$(cat /etc/mandrake-release)
    
        arch=$(uname -m)
        a="a"
        case "_$arch" in
    	    _a*) a="an";;
    	    _i*) a="an";;
        esac
        
        NUMPROC=`egrep -c "^cpu[0-9]+" /proc/stat`
        if [ "$NUMPROC" -gt "1" ]; then
            SMP="$NUMPROC-processor "
    	[ "$NUMPROC" = "2" ] && \
    	SMP="Dual-processor "
            if [ "$NUMPROC" = "8" -o "$NUMPROC" = "11" ]; then
                a="an"
    	else
    	    a="a"
            fi
        fi
    
        # This will overwrite /etc/issue at every boot.  So, make any changes you
        # want to make to /etc/issue here or you will lose them when you reboot.
    
        if [ -x /usr/bin/linux_logo ];then
    	/usr/bin/linux_logo -c -n -f | sed -e 's|\\|\\\\|g' > /etc/issue
    	echo "" >> /etc/issue
        else
    	> /etc/issue
        fi
        echo "$R" >> /etc/issue
        echo "Kernel $(uname -r) on $a $SMP$(uname -m) / \l" >> /etc/issue
        
        if [ "$SECURE_LEVEL" -le 3 ];then
    	echo "Welcome to ${HOST}" > /etc/issue.net
    	echo "$R" >> /etc/issue.net
    	echo "Kernel $(uname -r) on $a $SMP$(uname -m)" >> /etc/issue.net
        else	
    	echo "Welcome to Mandrake Linux" > /etc/issue.net
    	echo "-------------------------" >> /etc/issue.net
        fi
    elif [ $SECURE_LEVEL -ge 4 ]; then
        rm -f /etc/issue /etc/issue.net
    fi
    
    touch /var/lock/subsys/local
    where xactly would I add the execution of the file ? Thank you very much
    Last edited by micro_sucks; 05-23-2004 at 03:00 AM.

  4. #4
    Join Date
    Mar 2003
    Location
    Here
    Posts
    343
    After the 'touch ...' line.
    "Heisenberg may have been here."

  5. #5
    Join Date
    May 2003
    Location
    San Jose
    Posts
    37
    so after the touch line i would just add a
    /usr/local/bin/server_start

  6. #6
    Join Date
    Dec 1999
    Location
    Toronto
    Posts
    39,307
    Originally posted by micro_sucks
    so after the touch line i would just add a
    /usr/local/bin/server_start
    If 'server_start' is the name of the script (which is set as executable) and '/usr/local/bin' is the directory that contains the script.
    SEARCH FIRST... ASK SECOND Read the JL 'Community Help Posting Guidelines' before posting in the forums.

    Precompiled Redhat NTFS Modules

    Linuxplanet Tutorials

    If Linux doesn't have the solution, you have the wrong problem. ... Please do not send me a PM asking for help...

    Please read the search suggestion thread in JL Ideas

Posting Permissions

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