0

Sometimes TeamViewer disconnects itself (or gets disconnected) from its internet's main servers.

I am programming a script that will check if connection is lost and, if yes, kills and reopens the concerned process to make TeamViewer up and running again.

The problem is: I don't know how to discover that TeamViewer has lost its remote access capability (this is: the capability to be remotely accessed and controlled).

Tested until now:

  • Check TeamViewer process and/or daemon. Not valid: they keep working even after disconnected.
  • NICs review. Not valid: TeamViewer seems not to add any.
  • See the TeamViewer's main window. Not programmatically valid or easy to implement.

How can I programmatically know if TeamViewer has disconnected?

I don't know if this method differs between platforms, but at least I would like to know about a solution for some Linux shell. Bash if possible.

Sopalajo de Arrierez
  • 3,543
  • 4
  • 34
  • 52
  • Checking for the main window should certainly be reasonably possible though not necessarily the best solution. Does the local process listen on a port? Does that stay open in this mode? Is there a connection to a remote server that goes away when this happens? Is there no way to get the client itself to restart this connection? – Etan Reisner Mar 10 '15 at 15:22
  • @EtanReisner, the client itself gets sometimes disconnected to never reconnect again. Tested for v9 and v10. – Sopalajo de Arrierez Mar 10 '15 at 15:26
  • @EtanReisner, I am not sure the port listening method would be a good idea. What if TeamViewer changes this port randomly? Remember it differs from others remote control programs like VNC, that always listen on 5900TCP (or desired) port. – Sopalajo de Arrierez Mar 10 '15 at 15:28
  • @EtanReisner, checking `remote server connections` could not be a good method: I think this server (internet IP or domain) could change as desired by TeamViewers programmers. – Sopalajo de Arrierez Mar 10 '15 at 15:29
  • The point would be to check for the local process no longer listening on a port (assuming it was originally) so which port is was wouldn't matter. Similarly the idea was to watch for the local process no longer having a remote server connection (assuming it did originally) so again what that connection is doesn't matter. I don't know how `TeamViewer` works so I have no idea if either of those ideas make sense though. Honestly, I'd say go bug the `TeamViewer` people and tell them to fix the bug. – Etan Reisner Mar 10 '15 at 15:38

2 Answers2

1

Probably I'm late, but run into the same problem and found a possible solution. I'm using teamviewer 12.

I noticed that, in my case sometimes some GUI related process are not launched so the machine is not online in my computer and contact list, if I ssh it and check for the list of teamviewer processes using:

ps -ef | grep [t]eamviewer

I get just one process, the teamviewer daemon:

root      1808     1  0 09:22 ?        00:00:53 /opt/teamviewer/tv_bin/teamviewerd -d

But, when everything is fine I have:

root      1808     1  0 09:22 ?        00:00:53 /opt/teamviewer/tv_bin/teamviewerd -d
rocco    10975  8713  0 09:31 ?        00:00:58 /opt/teamviewer/tv_bin/wine/bin/wineserver
rocco    11064 10859  0 09:31 ?        00:00:33 /opt/teamviewer//tv_bin/TVGuiSlave.64 31 1
rocco    11065 10859  0 09:31 ?        00:00:28 /opt/teamviewer//tv_bin/TVGuiDelegate 31 1

So simply counting the number of process works for me..

#!/bin/bash

online() {
  ## Test connection
  ping -c1 www.google.com > /dev/null
  return $?
}

online
if (test $? -eq 0)
then
    network=$(ps -ef | grep [t]eamviewer | wc -l)
    if (test $network -gt 3)
    then
        echo Machine online, teamviewer connected
    else
        echo Machine online, teamviewer not connected, trying restart daemon
        sudo teamviewer --daemon restart
    fi
fi
rok
  • 2,574
  • 3
  • 23
  • 44
0

Have you considered trapping the signal(if possible) and executing a function that will restart TeamViewer.

Start it from a script and trap an exit signal

function restartTV {
    # re-start TeamViewrt
    sudo /etc/init.d/something start
}
trap finish EXIT            # or appropriate signal
sudo /etc/init.d/something stop
# Do the work...
Dragan
  • 455
  • 4
  • 12