top of page

Linux & Python_mail&subprocess

#!/bin/python

import subprocess

"""

FIND ERROS INSIDE YOUR LOGFILE WRITE THEM IN LIST & ITERATE THE LIST TO PICK THE EXACT ERROS YOU ARE SEEKING WRITE THE ERRORS IN A NEW FILE FOR ATTACHMENT AND ANALYSIS EMAIN THE ATTACHMENT TO DESIGNATED GROUPS OF PEOPLE THEN ENJOY THE REST OF YOUR DAY create bash wrapper to execute it { run it with crontab daily at 8am 0 8 * * * /app/documentum/run_ldap_sync_key_monitor.sh > /dev/null 2>&1 } /tmp/crontab.ClIguO" 18L, 1739C written crontab: installing new crontab # run the job with crontab daily

"""

PATH = "/app/documentum/dba/log/0001efd2/sysadmin/LDAPSynchronizationDoc.txt" lines = [ line for line in open(PATH)] ldaperrorline="DM_LDAP_SYNC_E_EXCEPTION_ERROR" for line in lines: if (ldaperrorline) in line: newpath = "/app/documentum/fwerescripts/ldapsyncerror.txt" new_file = open(newpath, "w") new_file.write(line) print(line)

#line.close() # send email notification for the errors found on the file command = "mail -s 'Testing file mail' meee@gmail.com < /app/documentum/fwerescripts/ldapsyncerror.txt" p = subprocess.Popen([command], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) (out,err) = p.communicate() print(out)

bottom of page