-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmail_ocxo_log.py
62 lines (51 loc) · 1.65 KB
/
mail_ocxo_log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: paulv
#
# Created: 13-03-2020
# Copyright: (c) paulv 2020
# Licence: <your licence>
#-------------------------------------------------------------------------------
import os
import re
import subprocess
import sys, traceback
import email
from time import time, sleep, gmtime, strftime, localtime
import zipfile
VERSION="1.0" # initial version
DEBUG = False
# here is where we store the errors and warnings
log_file = "/mnt/usb/ocxo.log"
zip_file = "/mnt/usb/bliley.zip"
mail_address = "[email protected]"
def mail_err_log():
'''
Just before a new day has been found by cron, this function emails the daily
local error logs, but only if an error condition has been reported.
'''
try:
print("zip the file")
os.chdir('/mnt/usb')
zipfile.ZipFile('bliley.zip', mode='w').write('ocxo.log', compress_type=zipfile.ZIP_DEFLATED)
except Exception as e:
print(e)
try:
if os.path.isfile(log_file):
with open(zip_file, "r") as fin:
f_data = fin.read()
# send it out as an attachement
cmd = 'mpack -s "Bliley log file" {} {}'.format(zip_file, mail_address)
print("mail_ocxo_log cmd : {}".format(cmd))
subprocess.call([cmd], shell=True)
except Exception as e:
send_mail("error", "Unexpected Exception in mail_ocxo_log() {0}".format(e))
return
def main():
print("Mail ocxo log Version {}".format(VERSION))
mail_err_log()
if __name__ == '__main__':
main()