简体   繁体   English

Raspberry Pi(Raspbian Linux风格)在wifi上运行脚本

[英]Raspberry Pi (Raspbian Linux flavor) run script on wifi up

Currently I am experience issues with the script automatic run after wifi adapter connects to a network. 目前,我在wifi适配器连接到网络后遇到脚本自动运行的问题。

After ridiculously extended research, I've made several attempts to add script to a /etc/network/if-up.d/. 经过可笑的扩展研究之后,我做了几次尝试将脚本添加到/etc/network/if-up.d/。 Manually my script works; 手动执行我的脚本; however it does not automatically. 但是它不会自动。

User permissions: 用户权限:

 ls -al /etc/network/if-up.d/*
 -rwxr-xr-x 1 root root  703 Jul 25  2011 /etc/network/if-up.d/000resolvconf
 -rwxr-xr-x 1 root root  484 Apr 13  2015 /etc/network/if-up.d/avahi-daemon
 -rwxr-xr-x 1 root root 4958 Apr  6  2015 /etc/network/if-up.d/mountnfs
 -rwxr-xr-x 1 root root  945 Apr 14  2016 /etc/network/if-up.d/openssh-server
 -rwxr-xr-x 1 root root   48 Apr 26 03:21 /etc/network/if-up.d/sendemail
 -rwxr-xr-x 1 root root 1483 Jan  6  2013 /etc/network/if-up.d/upstart
 lrwxrwxrwx 1 root root   32 Sep 17  2016 /etc/network/if-up.d/wpasupplicant -> ../../wpa_supplicant/ifupdown.sh

Also, I've tried to push the command directly in /etc/network/interfaces by adding a row 另外,我尝试通过添加一行直接在/ etc / network / interfaces中推送命令

post-up /home/pi/r/sendemail.sh

Contents of sendemail.sh : sendemail.sh的内容:

#!/bin/sh
python /home/pi/r/pip.py

After the reboot, nothing actually happen. 重新启动后,实际上没有任何反应。 I've even tried sudo in front 我什至在前面尝试过sudo

I assume that wpasupplicant is the thing which causes that, but I cannot get how to run my script in ifupdown.sh script under /etc/wpa_supplicant. 我假设wpasupplicant是导致此问题的原因,但是我无法在/ etc / wpa_supplicant下的ifupdown.sh脚本中获得如何运行脚本的方法。

Appreciate your help! 感谢您的帮助!

If you have no connectivity prior to initializing the wifi interface, I would suggest adding a cron job of a bash or python script that checks for connectivity every X minutes. 如果在初始化wifi接口之前没有连接,我建议添加一个bash或python脚本的cron作业,每隔X分钟检查一次连接。

Ping (host); 平(主机);

If host is up then run python commands or external command. 如果主机启动,则运行python命令或外部命令。

This is rather ambiguous but hopefully is of some help. 这是相当模棱两可的,但希望能有所帮助。

Here is an example of a script that will check if a host is alive; 这是一个脚本示例,它将检查主机是否还处于活动状态。

import re,commands


class CheckAlive:
def __init__(self):
        myCommand = commands.getstatusoutput('ping ' + 'google.com)
        searchString = r'ping: unknown host'

        match = re.search(searchString,str(myCommand))

        if match:
            # host is not alive
            print 'no alive, don't do stuff';
        else:
            # host is alive
            print 'alive, time do stuff';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM