Reputation: 535
I'm debugging a shell script so I add set -x at the beginning a code snippet are as below
tcpdump -i $interface host $ip_addr and 'port 80' -w flash/flash.pcap &
sudo -u esolve firefox /tor_capture/flash.html &
sleep $capture_time
but I noticed that the execution sequence is as below
++ sleep 5
++ sudo -u esolve firefox /tor_capture/flash.html
++ tcpdump -i eth0 host 138.96.192.56 and 'port 80' -w flash/flash.pcap
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
so the execution sequence is reversed compared to the command sequence in the script what is wrong with this and how to deal with it? thanks!
Upvotes: 1
Views: 115
Reputation: 62369
Since those lines are being backgrounded, I think the output from set -x
comes from the subshell that is spawned to run the program, and the main shell gets to the sleep
command before the subshells have proceeded to the point that they generate the output. That would explain why the sleep
command shows up first. With regards to the other two, I would think you might occasionally get them in the other order, as well, since there's no synchronization between the two - depending on how many CPUs you have, how busy the system is, etc., the timing between the subshells is pseudo-non-deterministic...
Upvotes: 1
Reputation: 47267
Do you need the first 2 lines to run as background processes?
If not, remove the &
at the end and try again.
Upvotes: 0