执行shell脚本遇到错误syntax error: unexpected "then" (expecting "}")

今天执行脚本的时候遇到错误,如下图:

root@ApFree:/usr/sbin# ./conntrack_num_graph.sh 

./conntrack_num_graph.sh: line 9: syntax error: unexpected "then" (expecting "}")

root@ApFree:/usr/sbin# 

 

我就纳闷了,这个脚本几天前是能正常执行的,今天执行怎么会出错,why?

cat脚本一看如下:

#!/bin/sh

SITENAME="apfree"聽聽聽聽聽 # change for your site

mkdir -p /mnt/rrd 

#iptables -L traffic -vnxZ -t filter > /tmp/traffic.tmp

# $1 = ImageFile, $2 = Time in secs to go back, $3 = RRDfile, $4 = GraphText

CreateGraph ()

{

聽聽聽聽聽聽聽聽# only run, if no other rrdtool is running

聽聽聽聽聽聽聽聽if [ -n "$(ps | grep rrdtool | grep -v grep)" ];then

                        return

聽聽聽聽聽聽聽聽fi

聽

聽聽聽聽聽聽聽聽rrdtool graph "${1}" -a PNG -s -"${2}" -w 550 -h 240 -v "" \

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽'DEF:count='${3}':conntrack_count:AVERAGE' \

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽'AREA:count#32CD32:Conntrack number' \

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽'HRULE:0#000000' -t "${4}"

}

聽

# build sum-graph

if [ ! -e /mnt/rrd/conntrack_num.rrd ] ; then

聽聽聽聽聽聽聽聽rrdtool create /mnt/rrd/conntrack_num.rrd -s 300 \

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽DS:conntrack_count:GAUGE:600:0:600000000 \

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽RRA:AVERAGE:0.5:1:600

fi

CONNTRACK_COUNT=`cat /proc/sys/net/netfilter/nf_conntrack_count`

rrdtool update /mnt/rrd/conntrack_num.rrd N:$CONNTRACK_COUNT

CreateGraph /mnt/rrd/conntrack_num.png 86400 /mnt/rrd/conntrack_num.rrd "conntrack from $SITENAME"

尼玛,这下才明白,有乱码!怪不得会出错呢!

 

为什么会有乱码呢?哦,原来是因为我之前把这个脚本删除了,然后从麦库记事本上把代码直接copy过来重新建立的脚本,才会出现这种情况!

 

解决办法:把乱码全部删除掉,再执行,就ok了,只不过这样真心很麻烦呀,如果看官们有更方便的办法,还请告诉我呀。

你可能感兴趣的:(shell脚本)