Bash script not working on a new dedicated server

Posted by Scott on Stack Overflow See other posts from Stack Overflow or by Scott
Published on 2012-10-20T16:53:27Z Indexed on 2012/10/20 17:00 UTC
Read the original article Hit count: 160

Filed under:
|

Recently I have migrated to the new dedicated server which is running on the same operating system - FreeBSD 8.2. I got a root account access and all permissions have been set properly.

My problem is that, the bash script I was running on the old server doesn't works on the new machine, the only error appearing while running the script is:

# sh script.sh
script.sh: 3: Syntax error: word unexpected (expecting ")")

Here is the code itself:

#!/usr/local/bin/bash

PORTS=(7777:GAME 11000:AUTH 12000:DB)
MESSG=""
for i in ${PORTS[@]} ; do
    PORT=${i%%:*}
    DESC=${i##*:}
    CHECK=`sockstat -4 -l | grep :$PORT | awk '{print $3}' | head -1`
    if [ "$CHECK" -gt 1 ]; then
        echo $DESC[$PORT] "is up ..." $CHECK
    else
        MESSG=$MESSG"$DESC[$PORT] wylaczony...\n"
        if [ "$DESC" == "AUTH" ]; then
            MESSG=$MESSG"AUTH is down...\n"
        fi
        if [ "$DESC" == "GAME" ]; then
            MESSG=$MESSG"GAME is down...\n"
        fi
        if [ "$DESC" == "DB" ]; then
            MESSG=$MESSG"DB is down...\n"
        fi

    fi
done

if [ -n "$MESSG" ]; then
    echo -e "Some problems ocurred:\n\n"$MESSG | mail -s "Problems" [email protected]
fi

I don't really code in bash, so I don't know why this happend...

© Stack Overflow or respective owner

Related posts about bash

Related posts about freebsd