exec-notify/notify
2020-12-26 15:15:54 +01:00

37 lines
785 B
Python
Executable File

#!/usr/bin/env python3
from sys import argv, stderr, stdin
import socket
from execNotifyDir import exec, config, mail
def main():
"""
echo <body> | ./notify
echo <body> | ./notify <subject>
./notify <subject> <body_1> <body_2> ... <body_n>
"""
BODY = None
subj = None
hostname = socket.gethostname()
if len(argv) >= 2:
subj = argv[1]
if len(argv) >= 3:
BODY = str(argv[2:])
if subj is None:
subj = "notify"
if BODY is None:
BODY = "=== stdin ===\n" + stdin.read()
SUBJECT = "{} | {}".format(hostname, subj)
print(BODY)
mail.sendMailOrWriteToFile(SUBJECT=SUBJECT, BODY=BODY)
if __name__ == '__main__':
main()
if mail.prevMailNotSent():
mail.informAboutOldMail()