64 lines
1.5 KiB
Python
64 lines
1.5 KiB
Python
![]() |
#!/usr/bin/env python
|
||
|
|
||
|
|
||
|
# This script sends an email with N last bytes from file X,
|
||
|
# X and N are given has command line arguments.
|
||
|
#
|
||
|
# Copyright (C) 2015 Jony Silva
|
||
|
# Wed 25 Nov 20:30:25 GMT 2015
|
||
|
#
|
||
|
# This program is free software: you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation, either version 3 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||
|
#
|
||
|
# enjoy :)
|
||
|
|
||
|
import smtplib
|
||
|
import sys
|
||
|
|
||
|
# Variables
|
||
|
RTYPE = sys.argv[1]
|
||
|
LINES = int(sys.argv[2])
|
||
|
|
||
|
|
||
|
# Send the email routine
|
||
|
def mail_send():
|
||
|
|
||
|
fromaddr = 'xxxxx@gmail.com'
|
||
|
toaddrs = 'xxxxxx@yahoo.com'
|
||
|
msg = 'Subject: Report\n\n%s' % (TEXT)
|
||
|
|
||
|
|
||
|
# Credentials
|
||
|
username = 'xxxxxx'
|
||
|
password = 'xxxxxxxxxxx'
|
||
|
|
||
|
# The actual mail send
|
||
|
server = smtplib.SMTP('smtp.gmail.com:587')
|
||
|
server.starttls()
|
||
|
server.login(username,password)
|
||
|
server.sendmail(fromaddr, toaddrs, msg)
|
||
|
server.quit()
|
||
|
print "Report done and sent."
|
||
|
|
||
|
|
||
|
# Grab last n bytes of text from the file
|
||
|
f = open(RTYPE, 'r')
|
||
|
f.seek(-LINES, 2)
|
||
|
TEXT = f.read(LINES)
|
||
|
f.close()
|
||
|
|
||
|
mail_send()
|
||
|
|
||
|
#print TEXT
|
||
|
|