Kill a process from parent shell within a shell script

Hi, I am looking for a solution for the following problem:

Im Using tcpdump within a shellskript started in a subshell by using brackets:

( /usr/sbin/tcpdump -i ... -c 1 )
  • - I want the outout of tcpdump saved in a variable
  • - Than tcpdump-Process in the Subshell should be killed
  • - and I want to use the variable in the parentshell for further steps of the skript

I hope you understand the circumstance and thanks in advance.

2retti

something like:

RET=`/usr/sbin/tcpdump -i ... -c 1`
echo $RET

notice the ` instead of '

The Problem is, this works only if the tcpdump gets an Output.
Due to the given parameters of tcpdump it is possible that there is no output and so tcpdump is listing and listing..... Thats the reason why i need the possiblity to kill the process.

great way of solving the issue without a subshell.

Then use a subshell where you can kill the tcpdump, but don't put your tcpdump in a subshell : a subshell can't return any value to its parent process.

Thanks, but I have no idea how this might look like. Can you give me a short explanation/example?

Dependends on how you want to kill the process : by a user entry, after a certain delay...
you can put in your script BEFORE the call to tcpdump a part of code like

(   read -p "press enter to stop the process" # for an user entry
    sleep 5m # waits 5 minutes (can be seconds (default) , hours, days...)
    killall tcpdump # or something with pkill (see man pkill)
) &