Find the answer to your Linux question:
Results 1 to 3 of 3
I consideer myself somewhat dangerous when writing scripts so be easy one me.... I have the following script: #! /bin/sh # File: sipfuzz # Protos SIP Fuzzing tool. # # ...
  1. #1
    Just Joined!
    Join Date
    Oct 2006
    Posts
    4

    How to kill background job in a script?

    I consideer myself somewhat dangerous when writing scripts so
    be easy one me....

    I have the following script:

    #! /bin/sh
    # File: sipfuzz
    # Protos SIP Fuzzing tool.
    #
    # Run Protos on any SIP enabled appliance.
    # See list of tests in PROTOS Test-Suite c07-sip.htm
    #
    if [ $# -ne 3 ] ; then
    echo 1>&2 Usage: sipfuzz '"IP Address Under Test"' '"Start Test #"' '"Stop Test #"'
    exit 127
    fi

    # Need a way to start wireshark or tcpdump here to capture
    # all of the packets for the test. Need to save in a file
    # that can be associated with the test(s) being run

    tcpdump -i eth0 -w SIPfuzz$2TO$3 &

    # Proper format:
    # java -jar c07-sip-r2.jar -touri 8502@100.3.28.10 -start 630 -stop 822

    java -jar c07-sip-r2.jar -touri $1 -start $2 -stop $3

    # Not sure the tcpdump will always be job #1?
    kill %1

    The problem is killing the tcpdump command. I thought the "kill %1" would work but for whatever reason, it doesn't....

    Any ideas how to stop the tcpdump process after the java code is completed?

    Thanks.

    Ray

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Yes indeed. It comes from a friend called $!. $! stores the PID of the last executed program.

    So we do the following instead:
    Code:
    #! /bin/sh
    # File: sipfuzz
    # Protos SIP Fuzzing tool.
    #
    # Run Protos on any SIP enabled appliance.
    # See list of tests in PROTOS Test-Suite c07-sip.htm
    #
    if [ $# -ne 3 ] ; then
    echo 1>&2 Usage: sipfuzz '"IP Address Under Test"' '"Start Test #"' '"Stop Test #"'
    exit 127
    fi
    
    # Need a way to start wireshark or tcpdump here to capture
    # all of the packets for the test. Need to save in a file
    # that can be associated with the test(s) being run
    
    tcpdump -i eth0 -w SIPfuzz$2TO$3 &
    tcpdpid=$!
    
    # Proper format:
    # java -jar c07-sip-r2.jar -touri 8502@100.3.28.10 -start 630 -stop 822
    
    java -jar c07-sip-r2.jar -touri $1 -start $2 -stop $3
    
    kill $tcpdpid
    Easy peasy.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Oct 2006
    Posts
    4
    Thanks. Piece of cake!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...