MyBB Internal: One or more warnings occurred. Please contact your administrator for assistance.
Shell Scripting, Needing someone to teach me some stuff.
SRCDS Steam group


Shell Scripting, Needing someone to teach me some stuff.
#1
Wink 
Hey guys Smile

I am busy creating a script for my community servers, the issue i am having is that i think i am doing stuff the long way. Also know that since Counter-Strike: Source has changed there file structure it makes thinks a lot harder.

We have 4 types of servers.

Counter-Strike: Source
Team Fortress 2
Left 4 Dead 2
Minecraft

I am needing some help make a management script for the dedibox.

Also can people mark out places where i can improve it. Also please state how i can do that.
Also if you do want to help me. you can contact me on steam if you like.
Steam: graham1995

Heres what i got so far, its taken a while to learn all this so please be nice Smile

Code:
#!/bin/bash

#Script created by Graham "Citrix" Newton

#Functions
NO_ARGS=0
CMD=$1
SRV=$2

# Text color variables
txtund=$(tput sgr 0 1)    # Underline
txtbld=$(tput bold)       # Bold
txtred=$(tput setaf 1)    # Red
txtgrn=$(tput setaf 2)    # Green
txtylw=$(tput setaf 3)    # Yellow
txtblu=$(tput setaf 4)    # Blue
txtpur=$(tput setaf 5)    # Purple
txtcyn=$(tput setaf 6)    # Cyan
txtwht=$(tput setaf 7)    # White
txtrst=$(tput sgr0)       # Text reset

txtund=$(tput sgr 0 1)          # Underline
txtbld=$(tput bold)             # Bold

#Minecraft - Functions
UpdateURL=http://ci.bukkit.org/job/dev-CraftBukkit/Recommended/artifact/target/craftbukkit-0.0.1-SNAPSHOT.jar

#If the user inputted the detials incorrectly
usage() {
    echo "${txtred}${txtbld}ERROR - User enter the information wrong${txtrst}"
    echo "./tmf.sh start|stop|update|restart|status|start-all|stop-all|update-all {Server}"
}

server_start() {
START=`ps x | grep SCREEN | grep $SRV | cut -d '?' -f 1`
    if [ ! -n "$SRART" ]; then
        if [ $SRV = "badwater" ]; then
            cd $SRV/orangebox; ./$SRV.sh; cd
            echo -e "${textgrn}${txtbld}$SRV --- Starting Up${txtrst}"
        else
            cd $SRV/css; ./$SRV.sh; cd
            echo -e "${textgrn}${txtbld}$SRV --- Starting Up${txtrst}"
         fi
    else
        echo -e "${textred}${txtbld}Error: $SRV --- Already Running${txtrst}"
    fi
}

server_stop() {
STOP=`ps x | grep SCREEN | grep $SRV | cut -d '?' -f 1`
    if [ ! -n "$STOP" ]; then
        echo -e "${textred}${txtbld}Error: $SRV --- Already Offline${txtrst}"
    else
        screen -dr $STOP -X quit
        echo -e "${txtgrn}${txtbld}$SRV --- now Offline${txtrst}"
    fi
}

server_update() {
    PRC=`ps x | grep SCREEN | grep $SRV | cut -d '?' -f 1`
        if [ ! -n "$PRC" ]; then
            PRC=999999999999
        else
            kill -9 $PRC
            echo -e "${txtgrn}${txtbld}$SRV has been successfully shutdown${txtrst}"
        fi
    STILLRUN=`ps x | grep $PRC | grep -v grep | cut -d '?' -f 1`
        if [ "$STILLRUN" = "$PRC" ]; then
            echo -e "${txtred}${txtbld}Error: $SRV was unable to shutdown!${txtrst}"
            exit
        else
            echo "Updating $SRV now"
            if [[ $SRV = 'badwater' || $SRV = 'controlpoint' ]]; then
                /home/server/1hldsupdatetool/./steam -command update -game tf -dir "/home/server/$SRV"
            else
                /home/server/1hldsupdatetool/./steam -command update -game "counter-strike source" -dir "/home/server/$SRV"
            fi
            echo -e "${txtgrn}${txtbld}$SRV has been updated successfully${txtrst}"
            server_start
        fi
}

server_status() {
for i in aim badwater deathrun event jailbreak left4dead2 minecraft skillsurf
do
    if [ "$(screen -ls | grep $i)" == "" ] ; then
        echo -e "$i --- ${txtred}${txtbld}Offline${txtrst}"
    else
        echo -e "$i --- ${txtgrn}${txtbld}Online${txtrst}"
    fi
sleep 1
done
}

server_start_all() {
echo -e "${txtblu}${txtbld}Only Starting up Source / Valve Servers${txtrst}"
for i in aim deathrun event jailbreak skillsurf
do
if [ "$(screen -ls | grep $i)" == "" ] ; then
    cd $i/css
    ./$i.sh
    cd
    echo -e "$i --- ${txtgrn}${txtbld}Online${txtrst}"
else
    echo -e "$i --- ${txtred}${txtbld}Already Running${txtrst}"
fi
sleep 1
done
}

server_stop_all() {
for i in aim deathrun event jailbreak skillsurf
do
if [ "$(screen -ls | grep $i)" == "" ] ; then
    echo -e "$i --- ${txtgrn}${txtbld}Already Offline${txtrst}"
else
    screen -dr $STOP -X quit
fi
sleep 1
done
}

case $CMD in
    start)
        server_start
    ;;
    stop)
        server_stop
    ;;
    update)
        server_update
    ;;
    start-all)
        server_start_all
    ;;
    stop-all)
        server_stop_all
    ;;
    status)
        server_status
    ;;
    restart)
        server_stop
        sleep 1
        server_start
    ;;
    *)
        usage
esac

exit 0
Reply


Messages In This Thread
Shell Scripting, Needing someone to teach me some stuff. - Citrix - 10-17-2011, 06:49 AM

Forum Jump:


Users browsing this thread: