执行shell脚本遇到错误syntax error: unexpected "then" (expecting "}")
今天执行脚本的时候遇到错误,如下图:
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 "}")的更多相关文章
- 不同系统执行相同shell脚本,出现Syntax error: "(" unexpected错误解决
例如shell脚本在centos系统中能正常执行,而在ubuntu系统中执行会出现类似Syntax error: "(" unexpected的错误,一般这种是因为sh与bash有 ...
- shell 报错:syntax error: unexpected end of file
有时执行脚本时会报错: [root@host1 shell]# sh -x test.sh + $'\r' : command not found test.: syntax error: unexp ...
- line 1: syntax error: unexpected word (expecting ")")
编译出来的程序在arm平台上运行时,出现下面的错误. / # wpa_supplicant -B -c/etc/wpa_wpa2.conf -iwlan0 /bin/wpa_supplicant: ...
- 【shell】真正解决syntax error:unexpected end of file?
今天写了个较长的shell脚本,结构嵌套比较多,最后运行时,出现了syntax error: unexpected end of file的错误. 这个之前碰到过,经常在win系统转移脚本文件到uni ...
- 同一脚本sh 脚本名 报Syntax error: "(" unexpected而./脚本名不报错,求解!!
同一脚本sh 脚本名 执行时报Syntax error: "(" unexpected:而./脚本名执行不报错,为什么呢 脚本内容如下: function usage(){ ech ...
- Shell脚本报错--syntax error near unexpected token for((i=0;i<$length;i++))
现象: shell脚本使用Nodepad++进行本地编辑,在编辑后上传到linux机器进行执行时提示“syntax error near unexpected token for((i=0;i< ...
- 解决shell 报错:syntax error: unexpected end of file
debug shell:执行 sh -x test.sh vi test.sh :set fileformat=unix :wq解决问题原因是我在windows pycharm 写的格式不符合uni ...
- 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 ...
- ( ! ) 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']"; 出现以下错误: 原因: 变量没有用花括号引起来 改为: $ ...
随机推荐
- C语言程序设计100例之(12):Eratosthenes筛法求质数
例12 Eratosthenes筛法求质数 问题描述 Eratosthenes筛法的基本思想是:把某范围内的自然数从小到大依次排列好.宣布1不是质数,把它去掉:然后从余下的数中取出最小的数,宣布它 ...
- vscode常用快捷键与插件推荐
一.vscode常用快捷键 1.新建文件:chtr+n 2.新开窗口:ctrl+shift+n 3.分屏:ctrl+1/2/3 4.切换文件:alt+1/2/3或ctrl+tab 5.关闭当前窗口: ...
- IT兄弟连 Java语法教程 流程控制语句 分支结构语句3
3 if-else if-else条件语句 if-else if-else的完整形式如下: if(判断条件A){ A语句块(判断条件A的值为true,执行) }else if(判断条件B){ B语句 ...
- mysql数据库的十种查询方式及多表查询
--mysql数据库的十种查询方式 -- (1)查询时起别名 SELECT id AS '编号',NAME AS '姓名',age AS '年龄' FROM student; -- (2)查询时添加常 ...
- hibernate手动设置的id无效的原因与解决方法
在使用Hibernate的过程中,发现手动设置的id(主键)无效,Hibernate仍然会在保存(调用Hibernate提供的merge()方法)的时候自动生成一个随机的id. 经过调试发现问题出在了 ...
- 为什么Redis 单线程却能支撑高并发?
作者:Draveness 原文:draveness.me/redis-io-multiplexing 推荐阅读 1. Java 性能优化:教你提高代码运行的效率 2. 基于token的多平台身份认证架 ...
- 2018-2-13-win10-uwp-手动锁Bitlocker
原文:2018-2-13-win10-uwp-手动锁Bitlocker title author date CreateTime categories win10 uwp 手动锁Bitlocker l ...
- Core源码(五)IQueryable(转)
如果要对Iqueryable进行深入的学习,那么对于拉姆达表达式.委托需要有一定了解.这里面拉姆达表达式就是匿名函数的一种写法,而委托我们常用FUNC和ACTION,这个都是对于delegate委托的 ...
- 你见过的最全面的 Python 重点
由于总结了太多的东西,所以篇幅有点长,这也是我"缝缝补补"总结了好久的东西. Py2 VS Py3 print成为了函数,python2是关键字 不再有unicode对象,默认st ...
- HashMap框架源码深入解读,面试不用愁
在Java Collections Framework的体系中中,主要有两个重要的接口,一个是List.Set和Queue所属的Collection,还有一个就是Map接口了.在上一篇文章中介绍了Li ...