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

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. Python画一棵漂亮的樱花树(不同种樱花+玫瑰+圣诞树喔)

    不少用Python(大多是turtle库)绘制的树图,感觉很漂亮,我整理了一下,挑了一些我觉得不错的代码分享给大家(这些我都测试过,确实可以生成喔~)one 樱花树 动态生成樱花效果图(这个是动态的) ...

  2. 【转】Ubuntu 16 安装 python 依赖出现 error: command 'i686-linux-gnu-gcc' failed with exit status 1

    问题 在 Ubuntu 下安装 python 依赖的时候出现以下错误 build/temp.linux-i686-3.5/_openssl.c:498:30: fatal error: openssl ...

  3. 开源的13个Spring Boot 优秀学习项目!超53K星,一网打尽!

    Spring Boot 算是目前 Java 领域最火的技术栈了,也是Java开发人员不得不掌握的技术,今天给大家整理了13个优质 Spring Boot 开源项目给大家参考,希望能够帮助到正在学习 S ...

  4. MySQL基础之STRAIGHT JOIN用法简介

    MySQL基础之STRAIGHT JOIN用法简介 引用mysql官方手册的说法: STRAIGHT_JOIN is similar to JOIN, except that the left tab ...

  5. 基于Node 的http转发demo,项目中请使用express+http-proxy-middleware

    var http = require("http"); var data = ''; function getData() { const options = { host: 'w ...

  6. 使用码云,GitHub进行版本控制,并通过WebHook进行自动部署

    我们通常需要在 PUSH 代码到远程仓库时,线上环境会自动进行代码同步,这时候就需要用到WebHook,它会自动回调我们设定的http地址. 通过请求我们自已编写的脚本,来拉取代码,实现与远程仓库代码 ...

  7. MySQL for OPS 11:优化

    写在前面的话 不管是作为运维还是作为 DBA,我们的工作都不是写 SQL,搞业务.更多的还是如何实现又好又快的给开发提供一个数据库环境和保障数据的安全性.前面的文章中读写分离,高可用,建立索引,分库分 ...

  8. C# download big file

    I had validated this.To download SSMS which is more than 500M+ static void Main(string[] args) { str ...

  9. C# read dll config

    public static SqlConnection GetSqlConnection() { Configuration myDllConfig = ConfigurationManager.Op ...

  10. Docker实用debug调试技巧锦集

    阅读约 20 分钟 『重用』容器名 但我们在编写/调试Dockerfile的时候我们经常会重复之前的command,比如这种docker run --name jstorm-zookeeper zoo ...