温州网站公司哪家好,wordpress edit lock,上海千途网站建设,哔哩哔哩网站建设模板2023年亲测 树莓派启动时自动邮件上报ip 首先开启qq邮箱smtp服务shell文件内容启动自动执行python文件注意事项 首先开启qq邮箱smtp服务
然后点击开启就会有授权码
shell文件内容
在自己的shell里#xff0c;运行echo $PATH#xff0c;把内容覆盖下面的path。 功能 作用就… 2023年亲测 树莓派启动时自动邮件上报ip 首先开启qq邮箱smtp服务shell文件内容启动自动执行python文件注意事项 首先开启qq邮箱smtp服务
然后点击开启就会有授权码
shell文件内容
在自己的shell里运行echo $PATH把内容覆盖下面的path。 功能 作用就是 测试网络系统是否成功联通命令ifconfig是否会有正常输出
#!/bin/bash
export PATH/home/pi/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/snap/bin
while true; do (echo ifconfig|grep 192.168) break;sleep 1;done;
python3 /home/pi/rePortIp.py 启动自动执行
主要工具crontab
crontab -e添加末尾如下ctrl s 保存然后ctrl x退出
reboot /home/pi/reportIp.shpython文件
python文件就是邮件发送了
# codingutf-8
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
import os
import time#发送内容t
def mail(t):retTruetry:msgMIMEText(t,plain,utf-8)msg[From]formataddr([Jack,my_sender]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号msg[To]formataddr([Rose,my_user]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号msg[Subject]树莓派IP地址获取上报 # 邮件的主题也可以说是标题serversmtplib.SMTP(smtp.qq.com, 587) # 发件人邮箱中的SMTP服务器端口是587server.login(my_sender, my_pass) # 括号中对应的是发件人邮箱账号、邮箱密码server.sendmail(my_sender,[my_user,],msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件server.quit() # 关闭连接except Exception: # 如果 try 中的语句没有执行则会执行下面的 retFalseretFalsereturn ret
# 获取ifconfig命令内容cmdifconfig |grep 192.t empty
while t empty:with os.popen(cmd,r) as p:t p.read()if not t:t emptytime.sleep(5)# 设置发件人和收件人信息
my_senderxxxxxxx.com # 自己的邮箱账号
my_pass xxx # 发件人邮箱密码(之前获取的授权码)
my_usermy_sender # 自己的邮箱账号retmail(t)
if ret:print(发送邮件成功)
else:print(发送邮件失败)
注意事项
1.确认开启了邮箱服务然后获得了授权 2. 确认有.sh文件和.py文件注意自己设置路径 3. 确认crontab设置okay 4.reboot试试吧