0

I'm trying to start one tcpdump in with my script. But I always get more than one. That's my ps output:

 1260 root     tcpdump -i br0 -C 1024 -w /media/usbhd-sdc2/pcaps/abfrage2.pcap
 1267 root     tcpdump -i br0 -C 1024 -w /media/usbhd-sdc2/pcaps/abfrage2.pcap

That's my code where I check if the uptime is the same like my start-time. If it's the same, it should start a tcpdump and it should also save the PID.
But why does it start a second one, does this happen, because my function readPID isn't fast enough?

 if [[ $timestart == $Zeit ]] || [[ "$pid1" != "" ]];then
                echo "First"
                if [[ $timeend != $Zeit ]];then
                        echo "second"
                        if [ "$pid1" == "" ];then
                                echo "third"
                                if [ "$port" != "" ];then
                                        echo "fourth"
                                        run_tcpdump port
                                        pid1=$(readPID1)
                                        echo $pid1
                                else

ReadPID funtion:

readPID1(){
ps -eo pid,args|awk '/abfrage2/ && ! /awk/{print $1}'
}

Update

Tcpdump function:

run_tcpdump(){
if [ "$1" == "port" ];then
  sudo tcpdump port $port -i br0 -C 1024 -w /media/usbhd-sd[b-c]2/pcaps/abfrage2.pcap &
else
  sudo tcpdump -i br0 -C 1024 -w /media/usbhd-sd[b-c]2/pcaps/abfrage2.pcap &
fi
}
3
  • Naming a shell function after a utility (which you also run) strikes me as just begging for surprises...
    – Jens
    Dec 21, 2015 at 12:43
  • @Jens Changed the name of the function, actually didn't thought of that, but it still doesn't work.
    – aha364636
    Dec 21, 2015 at 13:01
  • I can guess again that you may have another call of this function somewhere. Or called this script twice.
    – baldr
    Dec 21, 2015 at 15:04

1 Answer 1

1

I guess you might call your tcpdump function instead of system-wide package. rename it in your script to run_tcpdump for example. Not sure it is the root cause though.

Also make sure you have no tcpdump processes before you've started your script. Are you sure first process was not from previous run?

1
  • So I changed the name to run_tcpdump, still doesn't work.
    – aha364636
    Dec 21, 2015 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.