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
2
  • How are you authenticating SSH? Password or ssh key? – noitsbecky Jun 25 '15 at 15:44
  • I'm using an ssh key – Brian John Jun 25 '15 at 19:26
1

You probably just need to use nohup

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

2
  • I should have mentioned that I've tried using nohup as well. When I do that it exits with an error. $ nohup ssh <linux host> 'dd if=/dev/zero | nc <os x host> 20000' appending output to nohup.out $ echo $? 127 – Brian John Jun 25 '15 at 0: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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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