標籤:style blog color for cti 代碼
今天執行指令碼的時候遇到錯誤,如:
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/shSITENAME="apfree"聽聽聽聽聽 # change for your sitemkdir -p /mnt/rrd #iptables -L traffic -vnxZ -t filter > /tmp/traffic.tmp# $1 = ImageFile, $2 = Time in secs to go back, $3 = RRDfile, $4 = GraphTextCreateGraph (){聽聽聽聽聽聽聽聽# 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-graphif [ ! -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:600fiCONNTRACK_COUNT=`cat /proc/sys/net/netfilter/nf_conntrack_count`rrdtool update /mnt/rrd/conntrack_num.rrd N:$CONNTRACK_COUNTCreateGraph /mnt/rrd/conntrack_num.png 86400 /mnt/rrd/conntrack_num.rrd "conntrack from $SITENAME"
尼瑪,這下才明白,有亂碼!怪不得會出錯呢!
為什麼會有亂碼呢?哦,原來是因為我之前把這個指令碼刪除了,然後從麥庫記事本上把代碼直接copy過來重建立立的指令碼,才會出現這種情況!
解決辦法:把亂碼全部刪除掉,再執行,就ok了,只不過這樣真心很麻煩呀,如果看官們有更方便的辦法,還請告訴我呀。