0

有时TeamViewer会断开自身(或断开)与其互联网主服务器的连接。

我正在编写一个脚本来检查连接是否丢失,如果是,则终止并重新打开相关进程以使 TeamViewer 重新启动并运行

问题是:不知道怎么发现TeamViewer失去了远程访问能力(就是:远程访问和控制的能力)。

测试到现在:

  • 检查 TeamViewer 进程和/或守护程序。无效:即使在断开连接后它们也能继续工作。
  • NIC 审查。无效:TeamViewer 似乎没有添加任何内容。
  • 查看 TeamViewer 的主窗口。不是以编程方式有效或易于实施。

我如何以编程方式知道 TeamViewer 是否已断开连接

我不知道这种方法是否在平台之间有所不同,但至少我想知道一些 Linux shell 的解决方案。如果可能,猛击。

4

2 回答 2

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
于 2018-08-01T13:24:28.600 回答
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...
于 2015-03-10T15:29:23.127 回答