Im trying to measure bandwidth, packet loss, latency and jitter between two computers on a wireless 802.11s mesh connection.

Im trying to make a (my first) bash script that can do the following:

SSH to another computer and start logging data from services (ptpd, tcpdump, iperf).

Start the same processes on my own computer and start logging data.

Once the iperf transmission on my own computer is finished, it should SSH into the remote computer and kill the the services.

The idea is for this these three steps run in a for-loop, that increases the package size transmitted by iperf for each iteration and logs the resulting data.

I know how to start a process on the remote pc by ssh host@adress process.

I am however clueless on how to start multiple processes through SSH and logout, since the processes are terminated once I logout. I have looked at the screen and nohup commands, but don't know how to use them in a script.

Thanks in advance!

EDIT:

Thanks for all the help so far.

I got nohup to work now, it was pretty simple as people pointed out.
So now I got: ssh host@adress nohup ./script.sh > /dev/null 2>&1 & in the script on my main pc.
This starts a script on the remote pc just fine, and then logout of SSH. The next problem is how to execute the script on the remote pc as sudo, since this is needed by tcpdump.

After detaching, use screen -r to resume the session. There's also screen -x if the screen session was not detached, but went into background in some other way (or is actually still running on another terminal).

You can skip nohup entirely with screen or tmux, which I hear will keep processes running even if the connection to the remote host is dead (which is one of it's rather awesome strengths). I don't know how to do this though, so you will need to do your own reading by doing a man screen/man tmux after downloading it.

The answer is in your question. Use the screen or nohup commands. What don't you understand about how to use them?

Try

ssh host@address nohup command args &. The & puts the ssh shell into the background on the local system, which means that the ssh tunnel will remain as long as it can. But the nohup command will prevent the command running on the remote system from being terminated if, for any reason, the local ssh process terminates or loses connection to the remote host.

PS: You need to put quotes on the command you want to run (I use single quotes for good measure), otherwise it'll send the ssh session to the background rather than the command you want to run.
–
qweetJul 19 '12 at 16:51

Yeah I got nohup to work now, it was pretty simple as you point out. Now I got: ssh host@adress nohup ./script.sh > /dev/null 2>&1 &. This runs a script on the remote pc just fine. The next problem is to execute the script on the remote pc as sudo, since this is needed by tcpdump?
–
ThomasJul 19 '12 at 17:54