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:

  1. SSH to another computer and start logging data from services (ptpd, tcpdump, iperf).
  2. Start the same processes on my own computer and start logging data.
  3. 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!


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.

Trying ssh host@adress **sudo** nohup ./script.sh > /dev/null 2>&1 & doesnt work.

Any ideas?


If anybody is stuck with the same problem, I found a guide how to solve this:


4 Answers 4


Use screen.

Some useful shortcuts:

  • ctrl+a+c: create a new "window"
  • ctrl+a+n: go to next "window"
  • ctrl+a+p: go to previous "window"
  • ctrl+a+d: detach the session (it keeps running)

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).

Edit in 2021: Consider tmux as well as a nicer alternative to screen.

Or, for a single process, nohup — as mentioned in other answers.


From a --help on nohup;

Usage: nohup COMMAND [ARG]...
  or:  nohup OPTION
Run COMMAND, ignoring hangup signals.

Simply add an & to your nohup <whatever you want to run> command. It'll mean that unless you specifically kill the spawned nohup process, it ain't ever going to go away.

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.


You can prepend a program with nohup.

E.g. nohup myprogram &. That will start the program and send all output to a file called nohup.out. It will also catch the sigHUP when you log out.

Another solution is to run screen or tmux


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


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.
    – qweet
    Commented Jul 19, 2012 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?
    – Thomas
    Commented Jul 19, 2012 at 17:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .