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

root@ApFree:/usr/sbin# ./conntrack_num_graph.sh
./conntrack_num_graph.sh: line : 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 -h -v "" \
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽'DEF:count='${}':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 \
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽DS:conntrack_count:GAUGE::: \
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽RRA:AVERAGE:0.5::
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 /mnt/rrd/conntrack_num.rrd "conntrack from $SITENAME"

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

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

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

执行shell脚本遇到错误syntax error: unexpected "then" (expecting "}")的更多相关文章

  1. 不同系统执行相同shell脚本,出现Syntax error: "(" unexpected错误解决

    例如shell脚本在centos系统中能正常执行,而在ubuntu系统中执行会出现类似Syntax error: "(" unexpected的错误,一般这种是因为sh与bash有 ...

  2. shell 报错:syntax error: unexpected end of file

    有时执行脚本时会报错: [root@host1 shell]# sh -x test.sh + $'\r' : command not found test.: syntax error: unexp ...

  3. line 1: syntax error: unexpected word (expecting ")")

    编译出来的程序在arm平台上运行时,出现下面的错误. / # wpa_supplicant -B -c/etc/wpa_wpa2.conf  -iwlan0 /bin/wpa_supplicant: ...

  4. 【shell】真正解决syntax error:unexpected end of file?

    今天写了个较长的shell脚本,结构嵌套比较多,最后运行时,出现了syntax error: unexpected end of file的错误. 这个之前碰到过,经常在win系统转移脚本文件到uni ...

  5. 同一脚本sh 脚本名 报Syntax error: "(" unexpected而./脚本名不报错,求解!!

    同一脚本sh 脚本名 执行时报Syntax error: "(" unexpected:而./脚本名执行不报错,为什么呢 脚本内容如下: function usage(){ ech ...

  6. Shell脚本报错--syntax error near unexpected token for((i=0;i<$length;i++))

    现象: shell脚本使用Nodepad++进行本地编辑,在编辑后上传到linux机器进行执行时提示“syntax error near unexpected token for((i=0;i< ...

  7. 解决shell 报错:syntax error: unexpected end of file

    debug  shell:执行 sh -x test.sh vi test.sh :set fileformat=unix :wq解决问题原因是我在windows pycharm 写的格式不符合uni ...

  8. PHP错误 。Parse error: syntax error, unexpected T_INLINE_HTML, expecting T_ENDSWITCH or T_CASE or T_DEFAULT

    If you wan't to use the alternative syntax for switch statements this won't work: <div> <?p ...

  9. ( ! ) Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in D:\demo\code\yolo\index\index.php on li

    sql语句为:$sql="select count(*) from com where a_id=$v['id']"; 出现以下错误: 原因: 变量没有用花括号引起来 改为:  $ ...

随机推荐

  1. gradle中gredle -q 参数是什么意思

    很多地方在调用 gradle 命令时都加了 -q 参数.该参数用来控制 gradle 的日志级别,可以保证只输出我们需要的内容.

  2. 关闭Chrome浏览器的广告

    生活没有绝对的对与错:代码就不一样了,错了就编译不过,也正是因为这样,编程的人思维有时也会陷入一种狭隘中,这就是把工作和生活没有分开.Win10 右下角的广告就像程序调试中的"警告" ...

  3. Codeforces Round #597 (Div. 2) F. Daniel and Spring Cleaning 数位dp

    F. Daniel and Spring Cleaning While doing some spring cleaning, Daniel found an old calculator that ...

  4. Python程序中的线程操作-锁

    目录 一.同步锁 1.1 多个线程抢占资源的情况 1.1.1 对公共数据的操作 1.2 同步锁的引用 1.3 互斥锁与join的区别 二.死锁与递归锁 2.1 死锁 2.2 递归锁RLock 三.典型 ...

  5. spring cloud 2.x版本 Sleuth+Zipkin分布式链路追踪

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...

  6. app自动化测试初体验

    一.appium环境开启 1.开启MUMU模拟器/真机(真机需要开启“USB开发调试模式”),使用命令行adb devices检查设备是否正常连接 2.开启appium 双击运行appium应用 正常 ...

  7. 【LOJ#575】【LNR#2】不等关系(容斥,动态规划,分治FFT)

    [LOJ#575][LNR#2]不等关系(容斥,动态规划,分治FFT) 题面 LOJ 题解 一个暴力\(dp\),设\(f[i][j]\)表示考虑完了前\(i\)个位置,其中最后一个数在前面所有数中排 ...

  8. MySQL(10)---自定义函数

    MySQL(10)---自定义函数 之前讲过存储过程,存储过程和自定义函数还是非常相似的,其它的可以认为和存储过程是一样的,比如含义,优点都可以按存储过程的优点来理解. 存储过程相关博客: 1.MyS ...

  9. Python【day 13】内置函数02

    一.作用域相关-2个 1.locals() 参数是空 返回当前位置作用域的所有变量,返回的是字典 当前位置:函数内,返回局部变量 当前位置:函数外,返回全局变量 2.globals() 参数是空 返回 ...

  10. CAD总记不住?设计达人给你支招,最强口诀40条玩转设计

    绘图界有这样一个准则:绘图越快,玩的越6 相反的,CAD玩的很6 ,你的绘图效率一定不会差到哪里去,虽然不能说的太绝对,但你就操作如果玩转,一定你就操作能给你的绘图带来很多效率的提升. 当然后面就你就 ...