#!/usr/bin/env python3 from sys import argv import socket from typing import List from execNotifyDir import exec, config, mail def main(): if len(argv) >= 2: if not executeCommand(argv[1:]): exit(1) exit(0) def executeCommand(command: List) -> bool: keys = ['command', 'status', 'stderr', 'stdout'] code, stdout, stderr = exec.execute(command) values = [str(command), str(code), stderr, stdout] BODY = '' for key, value in zip(keys, values): BODY += '=== {} ===\n{}\n'.format(key, value) print(BODY) if code != 0: hostname = socket.gethostname() SUBJECT = '{} | {}'.format(hostname, str(command)) mail.sendMailOrWriteToFile(SUBJECT=SUBJECT, BODY=BODY) return False else: return True if __name__ == '__main__': main() if mail.prevMailNotSent(): mail.informAboutOldMail()