我正在编写一个Shell脚本来启动Zookeeper
服务器并在zookeeper.out
nohup
文件中写入日志,但是当我尝试启动它时,出现以下错误:>
> : not foundh: 2: zookeeper.sh:
: not foundh: 8: zookeeper.sh:
: not foundh: 10: zookeeper.sh:
---- Starting Zookeeper ----
: not foundh: 12: zookeeper.sh:
: not foundh: 13: zookeeper.sh: }
: not foundh: 14: zookeeper.sh:
---- Stopping Zookeeper ----
: not foundh: 17: zookeeper.sh:
: not foundh: 18: zookeeper.sh: }
: not foundh: 19: zookeeper.sh:
: not foundh: 21: zookeeper.sh: stop
: not foundh: 22: zookeeper.sh: start
: not foundh: 23: zookeeper.sh: }
: not foundh: 24: zookeeper.sh:
zookeeper.sh: 25: zookeeper.sh: Syntax error: word unexpected (expecting "in")
我似乎不明白我在做什么错。
脚本:
#!/bin/sh
JAVA_HOME=""
KAFKA_HOME="/home/ubuntu/maxFlow/kafka_2.12-1.1.0"
APP_HOME="/home/ubuntu/maxFlow/"
APP_NAME=max-flow-0.0.1-SNAPSHOT
APP_PORT=80
start() {
echo "---- Starting Zookeeper ----"
nohup $KAFKA_HOME/bin/zookeeper-server-start.sh $KAFKA_HOME/config/zookeeper.properties > /dev/null 2>&1 & > zookeeper.out
}
stop() {
echo "---- Stopping Zookeeper ----"
nohup $KAFKA_HOME/bin/zookeeper-server-stop.sh > /dev/null 2>&1 & > zookeeper.out
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "No case"
exit 1
;;
esac
exit 0;
我从https://www.shellscript.sh/case.html
获取了脚本的语法。谢谢
答案 0 :(得分:0)
我在虚拟机上,并使用Windows记事本启动了编辑器,它将脚本转换为dos
。因此,我最终安装了dos2unix
,该脚本用于转换脚本。然后,脚本起作用了。