Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 在终止前一个命令之前,不执行第二个命令_Bash_Neo4j - Fatal编程技术网

Bash 在终止前一个命令之前,不执行第二个命令

Bash 在终止前一个命令之前,不执行第二个命令,bash,neo4j,Bash,Neo4j,我对bash很陌生。我正在运行bash脚本。它应该启动Neo4j,然后执行一系列位于名为“cypher.ex1”文件中的查询。代码如下: #!/bin/bash ./bin/neo4j console ./bin/cypher-shell -u neo4j -p 123456 --file cypher.ex1 为了使用Cypher shell,我们应该首先启动Neo4j服务。因此,这一行: ./bin/neo4j console 启动Neo4j,以便可以使用以下行使用cypher shel

我对bash很陌生。我正在运行bash脚本。它应该启动Neo4j,然后执行一系列位于名为“cypher.ex1”文件中的查询。代码如下:

#!/bin/bash
./bin/neo4j console
./bin/cypher-shell -u neo4j -p 123456 --file cypher.ex1
为了使用Cypher shell,我们应该首先启动Neo4j服务。因此,这一行:

./bin/neo4j console
启动Neo4j,以便可以使用以下行使用cypher shell:

./bin/cypher-shell -u neo4j -p 123456 --file cypher.ex1
问题在于,由于
/bin/neo4j控制台
启动了neo4j服务,因此除非我按下“Ctrl+C”,否则不会执行下一个命令(
/bin/cypher shell-u neo4j-p 123456——file cypher.ex1
)。如果我按“Ctrl+C”,Neo4j服务将停止,以下命令也不会执行(我得到“连接被拒绝”错误)。我应该怎么做才能启动Neo4j服务,然后在这个bash脚本中运行cypher shell


我尝试了中给出的解决方案。他们都不为我工作。例如,当我使用“(command1&);command2”(正如在建议的主题中所建议的那样)执行代码时,我的脚本会自动执行两次。第一次执行command2时,由于command1未执行,我得到“connection Rejected”错误;第二次执行command1而不执行command2。

正如Q/A中第一次回答中提到的,您应该以以下方式执行命令:

#!/bin/bash
./bin/neo4j console &
./bin/cypher-shell -u neo4j -p 123456 --file cypher.ex1
这将在后台运行
/bin/neo4j控制台
。因此,您需要注意此过程,并在需要时停止此过程:

PID=$(jobs -l |awk '{print $2}')
kill $PID

此外,在脚本中,在继续执行其他操作之前,您应该始终检查以确保
cd
命令工作正常,否则脚本的其余部分可能会在错误的位置运行。看见(顺便说一句,运行脚本有助于避免许多常见错误。)@Sorin不,它没有。我尝试了该主题中建议的解决方案。当我使用“(command1&);command2”(正如您在建议的主题中所建议的那样)执行代码时,我的脚本会自动执行两次。第一次执行command2时,由于command1未执行,我得到“connection Rejected”错误;第二次执行command1而不执行command2。