最近我已经迁移到运行在同一操作系统上的新的专用服务器 - FreeBSD 8.2。我获得了 root 帐户访问权限,并且所有权限都已正确设置。
我的问题是,我在旧服务器上运行的 bash 脚本在新机器上不起作用,运行脚本时出现的唯一错误是:
# sh script.sh
script.sh: 3: Syntax error: word unexpected (expecting ")")
这是代码本身:
#!/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" yet@another.com
fi
我并没有真正用 bash 编写代码,所以我不知道为什么会发生这种情况......