有时TeamViewer 会自行断开与其互联网主服务器的连接(或断开连接)。
我正在编写一个脚本,该脚本将检查连接是否丢失,如果是,则终止并重新打开相关进程,以再次使 TeamViewer 启动并运行。
问题是:我不知道如何发现TeamViewer失去了远程访问能力(即:被远程访问和控制的能力)。
测试到目前为止:
- 检查 TeamViewer 进程和/或守护程序。无效:即使断开连接,它们仍能继续工作。
- NIC 审查。无效:TeamViewer 似乎没有添加任何内容。
- 查看 TeamViewer 的主窗口。在编程上不有效或易于实现。
如何以编程方式了解 TeamViewer 是否已断开连接?
我不知道这个方法在平台之间是否有所不同,但至少我想知道一些Linux shell的解决方案。如果可能的话,请 bash 。
最佳答案
可能我迟到了,但遇到了同样的问题并找到了可能的解决方案。我使用的是 teamviewer 12。
我注意到,就我而言,有时某些 GUI 相关进程未启动,因此机器在我的计算机和联系人列表中未在线,如果我使用 ssh 并检查 teamviewer 进程列表:
ps -ef | grep [t]eamviewer
我只得到一个进程,即 teamviewer 守护进程:
root 1808 1 0 09:22 ? 00:00:53 /opt/teamviewer/tv_bin/teamviewerd -d
但是,当一切都很好时,我有:
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
所以简单地计算进程数量对我来说是有效的..
#!/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
关于linux - bash shell : How can I know if TeamViewer has disconnected?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28967534/