0

I'm trying to run a network throughput test between an OS X and a Linux host. I'd like to be able to measure the sustained throughput from the Linux host to the OS X host over time. I'd like to wrap this up into a single script so that I can easily run it as I make changes to the network.

My approach so far has been to start netcat on the OS X host listening on a port (nc -l -k 20000 > /dev/null). Then I'll start netcat on the Linux host and have it send data to the OS X host (ssh <Linux host> 'dd if=/dev/zero | nc <OS X host> 20000 2>&1'). After that I'll run netstat -i 1 to measure the throughput and log it to a file.

This all works great when I open 3 terminal windows and run these commands in the foreground. However, when I try to run either of the netcat commands in the background, the ssh process exits. I've tried using & and -f to background the ssh process.

Here is what the full script looks like so far:

#!/usr/bin/env bash

set -o errexit

nc -l -k 20000 > /dev/null &
LISTEN_PID=$!

ssh <linux host> 'dd if=/dev/zero | nc <os x host> 20000 2>&1' &
SEND_PID=$!

echo "Listen: ${LISTEN_PID}, Send: ${SEND_PID}"

netstat -i 1
Brian John
  • 161
  • 1
  • 4

2 Answers2

1

You probably just need to use nohup

http://linux.die.net/man/1/nohup

noitsbecky
  • 616
  • 3
  • 13
  • I should have mentioned that I've tried using nohup as well. When I do that it exits with an error. `$ nohup ssh 'dd if=/dev/zero | nc 20000'` `appending output to nohup.out` `$ echo $?` `127` – Brian John Jun 25 '15 at 00:12
  • @BrianJohn I've tried the exact same command and it works as expected. Then again, even without the nohup, it works as well... – noitsbecky Jun 25 '15 at 15:46
0

You might use screen -d script.sh to start the script with screen in detached mode.

Mauricio López
  • 974
  • 4
  • 9