In bash, I'm running iftop tool with text output. It's a tool that is monitoring network and writting the results periodicaly in the standard output (by default the terminal but could be something else, a file). It's running in foreground until I stop it with ctrl + C
I would like to make it running for a certain period of time (1 minute for example), and then stop the process automatically
How can I make this in bash ?
Here is what I already tried:
sudo iftop -nNPt -L 100 -i wlp0s20f3 > iftop.out & pid=$!; sleep 20; sudo kill $pid
But, 1) it does not kill the process and 2) it does not redirect to the file