【发布时间】:2017-09-27 09:07:29
【问题描述】:
我正在编写一个 shell 脚本。我想运行 2 个命令。第一个命令是:
/zap.sh -daemon -config api.disablekey=true -config view.mode=attack
一旦我运行它,它将监听一个端口 (9090)。
当它监听那个端口时,我想运行另一个命令(一个 curl 请求)
这就是我的代码现在的样子
echo "start daemon";
~/Desktop/research/ZAP/zap.sh -daemon -config api.disablekey=true -config view.mode=attack
echo "deamon is running";
a=$( curl "http://localhost:8500/JSON/spider/action/scan/?zapapiformat=JSON&url=http://localhost:8080/Danial/login&contextName=" )
由于第一个命令仍在运行(它侦听端口),我无法转到下一个命令。有没有办法异步执行此操作或其他方式执行此操作?
【问题讨论】:
-
将
&附加到第一个命令以在后台运行它。使用pid=$!作为下一个命令来收集衍生进程的PID。当您不再需要生成的进程时,使用kill "$pid"杀死它。
标签: linux multithreading bash shell sh