树莓派py文件自动运行
1.Python 代码 autowifi.py,放在 /home/pi 目录下:
|
1
2
3
4
5
6
7
8
|
#!/usr/bin/pythonimport os, timewhile True: if '192' not in os.popen('ifconfig | grep 192').read(): print '\n****** wifi is down, restart... ******\n' os.system('sudo /etc/init.d/networking restart') |
2.Shell脚本autowifi.sh,也放在 /home/pi 目录下:
|
1
2
|
#!/bin/shpython /home/pi/autowifi.py & |
3.开机自动启动以上脚本:在终端窗口执行以下命令即可
|
1
2
3
4
|
sudo cp -f /home/pi/autowifi.sh /etc/init.d/sudo chmod +x /etc/init.d/autowifi.shsudo chown root:root /etc/init.d/autowifi.sh sudo update-rc.d autowifi.sh defaults |