If network interface switches kill process and res

2019-09-15 18:33发布

I'm going to try and explain this as best as possible. I've been working on a project for iPhone that utilizes autossh to forward a port on start up and maintain it. Problem is when enabling/disabling mobile/wifi connection autossh does not switch to the active interface.

Example: I start up autossh with 3G data connection then switch on wifi, but autossh continues to utilize 3G data connection. I then turn 3G off and bam autossh fails to connect even after switching 3G back on... Same goes for wifi... Startup with wifi enabled and connected, then turn on 3G and disable/lose wifi connection autossh will fail to connect again.

So what I basically need to do is restart autossh whenever the interfaces switch but only once per switch if that makes sense so it's not killing over and over again.

I came up with a line of code but it's not good enough

  if [[ $(ifconfig pdp_ip0 |grep inet) && ! $(ifconfig en0 |grep inet) ]]; then
  echo true
  else
  echo false 

  if [[ ! $(ifconfig pdp_ip0 |grep inet) && $(ifconfig en0 | grep inet ]]; then  
  echo true
  else 
  echo false

A loop would probably do it but it needs to kill once per true condition & needs to wait until its false then true again. God this is hard to explain.

0条回答
登录 后发表回答