连接到wifi时,在linux上自动运行python脚本

时间:2017-04-19 04:38:42

标签: python linux python-3.x scripting

每当我连接到我的拼贴wifi时,我必须登录才能访问互联网。所以我制作了一个python脚本来自动登录网络。但我必须手动运行脚本。我想在笔记本电脑连接到互联网时自动运行脚本。

1 个答案:

答案 0 :(得分:0)

取自https://askubuntu.com/a/360262

您可以编写存储在/etc/NetworkManager/dispatcher.d/中的调度程序脚本,例如内容(未经测试):

#!/bin/bash
# nm sets this values
INTERFACE=$1
ACTION=$2

SSID="yourssid"
ESSID=`iwconfig $INTERFACE | grep ESSID | cut -d":" -f2 | sed 's/^[^"]*"\|"[^"]*$//g'`

if [ "$INTERFACE" == "wlan0" ]; then
  if [ "$SSID" == "$ESSID" ] && [ "$ACTION" == "up" ]; then
    #activate dropbox sync
  else
    #deactivate dropbox sync
  fi
fi