E-Mail-Backup
This commit is contained in:
parent
9cdbbf0113
commit
c2fe9fbdee
3 changed files with 70 additions and 2 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -214,6 +214,7 @@ pip-log.txt
|
|||
#Mr Developer
|
||||
.mr.developer.cfg
|
||||
|
||||
#Backups
|
||||
#eigene
|
||||
Backup/
|
||||
.csv
|
||||
passwort.py
|
||||
|
|
66
Fremddateien/send.py
Normal file
66
Fremddateien/send.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/python
|
||||
# (c) by hakermania http://ubuntuforums.org/showthread.php?t=1472520&p=12104667#post12104667
|
||||
|
||||
import os, re
|
||||
import sys
|
||||
import smtplib
|
||||
import passwort # eigene Passwoerter in getrennter Datei
|
||||
|
||||
#from email.mime.image import MIMEImage
|
||||
from email import encoders
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.base import MIMEBase
|
||||
from email.MIMEText import MIMEText
|
||||
|
||||
|
||||
SMTP_SERVER = 'mail.gmx.net'
|
||||
SMTP_PORT = 587
|
||||
|
||||
sender = passwort.sender
|
||||
password = passwort.password
|
||||
|
||||
recipient = sys.argv[1]
|
||||
subject = ''
|
||||
message = sys.argv[3]
|
||||
|
||||
def main():
|
||||
msg = MIMEMultipart()
|
||||
msg['Subject'] = sys.argv[2]
|
||||
msg['To'] = recipient
|
||||
msg['From'] = "Raspberry Pi <" + sender + ">"
|
||||
|
||||
|
||||
part = MIMEText('text', "plain")
|
||||
part.set_payload(message)
|
||||
msg.attach(part)
|
||||
|
||||
session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
|
||||
|
||||
session.ehlo()
|
||||
session.starttls()
|
||||
session.ehlo
|
||||
|
||||
session.login(sender, password)
|
||||
|
||||
fp = open(sys.argv[4], 'rb')
|
||||
msgq = MIMEBase('audio', 'audio')
|
||||
msgq.set_payload(fp.read())
|
||||
fp.close()
|
||||
# Encode the payload using Base64
|
||||
encoders.encode_base64(msgq)
|
||||
# Set the filename parameter
|
||||
filename=sys.argv[4]
|
||||
msgq.add_header('Content-Disposition', 'attachment', filename=filename)
|
||||
msg.attach(msgq)
|
||||
# Now send or store the message
|
||||
qwertyuiop = msg.as_string()
|
||||
|
||||
|
||||
|
||||
session.sendmail(sender, recipient, qwertyuiop)
|
||||
|
||||
session.quit()
|
||||
os.system('notify-send "Email sent"')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
zufall=0
|
||||
PFAD="/var/www/" #Pfad zum Web-Verzeichnis
|
||||
r=0 # Backup-Zahl auf Null setzen
|
||||
r=998 # Backup-Zahl auf Null setzen
|
||||
IFS="; " #Spezial-Variable, enthält Trennzeichen zum Trennen von Luftdruck und -temperatur
|
||||
if [ $1 ] # if- und case- Abfrage für Startparameter
|
||||
then
|
||||
|
@ -91,6 +91,7 @@ do
|
|||
if [ "$r" == "1000" ] # und alle 1000 Durchgänge Sicherung anfertigen
|
||||
then
|
||||
cp /home/pi/Temperaturmessung/dygraph.csv /home/pi/Temperaturmessung/dygraph.csv.bak
|
||||
python send.py "l.winkler23@me.com" "Backup" "" "dygraph.csv"
|
||||
echo "Backup"
|
||||
r=0
|
||||
fi
|
||||
|
|
Reference in a new issue