Reputation: 1086
I am writing a shell script. I want to run 2 commands. The first command is:
/zap.sh -daemon -config api.disablekey=true -config view.mode=attack
Once i run this it will listen a port (9090).
While it listen to that port I want to run a another command (a curl request)
This is how my code looks now
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=" )
Since the first command still running (it listen to the port) I can't go to the next command. Is there a way to do this asynchronously or some other way to do this?
Upvotes: 0
Views: 1037
Reputation: 15246
While you probably don't need anything so elaborate for this, you might peek at running a "coprocess".
http://wiki.bash-hackers.org/syntax/keywords/coproc
Upvotes: 0
Reputation: 2474
You can run the first command in background, which will allow you to execute other commands while the first one is running.
Read more on this: https://www.maketecheasier.com/run-bash-commands-background-linux/
It basically looks like this:
#!/bin/bash
command1 &
command2
Upvotes: 3