-1

How can I achieve the following using python or bash?

  1. iperf -s -B 234.5.6.7 -u -f m -i 1
    • let the above command run for 5 seconds
    • kill the above process (e.g. killall iperf)
  2. iperf -s -B 234.5.6.8 -u -f m -i 1
    • let the above command run for 5 seconds
    • kill the above process (eg killall iperf)
  3. and so on...
entpnerd
  • 10,049
  • 8
  • 47
  • 68

1 Answers1

0

$! in bash will give you the pid of the last background process. So you could do something quick and dirty like this in bash

#!/bin/bash 

iperf -s -B 234.5.6.7 -u -f m -I 1 &
FOO = $!
sleep 5
kill $FOO
iperf -s -B 234.5.6.8 -u -f m -I 1 &
FOO = $!
sleep 5
kill $FOO

Lather rinse repeat...

We can then refactor this to a for loop

#!/bin/bash

for IP in 234.5.6.7 234.5.6.8
do
  iperf -s -B $IP -u -f m -I 1 &
  FOO = $!
  sleep 5
  kill $FOO
done
Doon
  • 19,719
  • 3
  • 40
  • 44