执行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']"; 出现以下错误: 原因: 变量没有用花括号引起来 改为: $ ...
随机推荐
- [Vue专题] 对比vue-cli2.x和vue-cli3.x的搭建
简介:深入了解脚手架vue-cli2.x版本与3.x版本构建项目的区别 搭建前提条件: node环境 node是傻瓜式安装的,直接去官网下载安装不断下一步 命令行输入node -v查询版本号,有版本号 ...
- Tree-Shaking性能优化实践 - 原理篇
Tree-Shaking性能优化实践 - 原理篇 一. 什么是Tree-shaking 先来看一下Tree-shaking原始的本意 上图形象的解释了Tree-shaking 的本意,本文所说的前 ...
- Java 程序员应在2019年学习的10条面向对象(OOP)设计原则
面向对象的设计原则 是 OOP 编程的核心,但是我看到大多数 Java 程序员都在追求诸如 Singleton 模式,Decorator 模式或 Observer 模式之类的设计模式,而对学习面向 ...
- 【linux】linux命令--uptime查看机器存活多久和平均负载 解读平均负载含义
一.uptime命令,查看机器存活时间和平均负载 键入命令: uptime 该结果和 top命令查看结果最上面一行的 是一样的显示. 返回数据介绍: #当前服务器时间: 19:56:44 #当前服务器 ...
- mysql - 锁及事务的认识
mysql事务特性:一致性原子性隔离性持久性 //mysql 事务隔离级别 读未提交 读未提交的数据 读已提交 读已提交的数据 串行序列化 一个事务完成了再执行另一个事务 可重复读(数据库默认) 就算 ...
- Java生鲜电商平台-用户管理的架构与实战
Java生鲜电商平台-用户管理的架构与实战 在电商后台中,用户管理是运营人员管理用户的模块.这里的用户区别于运营人员,会在权限的角色管理中分别阐述.这里的用户包含平台的一般用户,会员用户等.本文将分享 ...
- FCC---Make Motion More Natural Using a Bezier Curve--- juggling movement
This challenge animates an element to replicate the movement of a ball being juggled. Prior challeng ...
- linux远程桌面连接 VNC Server
更新源 # sudo apt-get update 安装vnc4server # sudo apt-get install vnc4server 修改vnc远程连接密码 # vncpasswd 编辑v ...
- JavaScriptCore
在移动的混合开发中经常用到OC与JS的交互,就涉及iOS中的JavaScriptCore类,下面终结如下 JavaScriptCore中的类 在项目中引入JavaScriptCore后,链到头文件中, ...
- NSURLSession的知识小记
1.NSURLSession的使用流程 使用NSRULSession对象创建Task, 然后执行Task 2.获取NSURLSession ()获得共享的Session + (NSURLSession ...