Skip to content

Instantly share code, notes, and snippets.

@Suzhou65
Last active September 26, 2020 03:56
Show Gist options
  • Select an option

  • Save Suzhou65/aed64f0c27bf8c895e7ab085cb95c466 to your computer and use it in GitHub Desktop.

Select an option

Save Suzhou65/aed64f0c27bf8c895e7ab085cb95c466 to your computer and use it in GitHub Desktop.
Raspberry Pi Automatically Report
import re
import os
import sys
import socket
import smtplib
import datetime
import subprocess
from subprocess import PIPE
from subprocess import Popen
from email.mime.text import MIMEText

p1 = Popen(["ps", "-x"], stdout=PIPE)
p2 = Popen(["grep", "HentaiAtHome"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close()

psawk = ['awk","NR==1{print$3,$5}"]
         p3 = subprocess.Popen(psawk, stdin=p2.stdout, stdout=subprocess.PIPE)
         p2.stdout.close()
         p4 = p3.communicate()[0];
         output = p4.replace('R','S').replace('l','').replace('+','').replace(' ','').replace('-','').decode("utf-8")
         p3.stdout.close()
         
def hathstats():
         state = output
    return (state)

match = re.search(r'pjava',output)
         if match:
            sys.exit()
         else:
            to = '[email protected]'
            user = '[email protected],'
            password = '1919'
            smtpserver = smtplib.SMTP('smtp.114514.com', 234)
            smtpserver.ehlo() 
            smtpserver.starttis()
            smtpserver.ehlo
            smtpserver.login(user, password)
            today = datetime.datetime.now() 
 
            alert = 'Hentai@Homet Clients State Report %s' %hathstats()
            msg = MIMEText(alert)
            msg['Subject'] = '[ WARNING ] Hentai@Home ALERT %s % today.strftime('%Y-%m-%d %H:%M:%S')
            msg['From'] = user
            msg['To'] = to
            smtpserver.sendmail(user,(to), msg.as_string()
            smtpserver.quit()
            sys.exito
pi@raspberrypi:~/python $ python test.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment