1、检查是否安装crontab
apt-get install cron
说明以及安装过了
一般cron检索的crontab文件。这个文件在默认情况下:/etc/crontab
执行文件在 /etc/init,d/cron
重启: /etc/init.d/cron restart
2、检查安装python
apt-get instll python
获取ip以及发送邮箱的功能
#!/bin/bash
import os
# smtplib 用于邮件的发信动作
import smtplib
# email 用于构建邮件内容
from email.mime.text import MIMEText
#获取ipv6地址
ip6s = [ip.split('/')[0] for ip in os.popen("ip addr | grep 'inet6 '|awk '{print $2}'").readlines()]
#获取ipv4地址
ip4s = [ip.split('/')[0] for ip in os.popen("ip addr | grep 'inet '|awk '{print $2}'").readlines()]
# 发信方的信息:发信邮箱,QQ 邮箱授权码
from_addr = '发信方的信息'
password = 'QQ 邮箱授权码'
# 收信方邮箱
to_addr = '收信方邮箱'
# 发信服务器
smtp_server = 'smtp.qq.com'
msg_text = 'ipv4地址集: '+str(ip4s)+'\n\n'+'ipv6地址集: '+str(ip6s)
# 邮箱正文内容,第一个参数为内容,第二个参数为格式(plain 为纯文本),第三个参数为编码
msg = MIMEText(msg_text,'plain','utf-8')
server = smtplib.SMTP_SSL(smtp_server)
server.connect(smtp_server,465)
server.login(from_addr, password)
server.sendmail(from_addr, to_addr, msg.as_string())
# 关闭服务器
server.quit()
linux crontab记时事件:
python在文件里的执行目录一定需要写为 完全路径
最后的验证
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!