2021-07-22 13:01:18 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from sys import argv, stderr, stdin
|
|
|
|
import socket
|
|
|
|
|
|
|
|
from de.p1st.exec_notify.lib import exec, config, mail
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
"""
|
2021-11-23 19:18:38 +01:00
|
|
|
Send an email with some content and optionally specify an email subject.
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
echo <body> | de-p1st-notify
|
|
|
|
|
|
|
|
echo <body> | de-p1st-notify <subject>
|
|
|
|
|
|
|
|
de-p1st-notify <body>
|
|
|
|
|
|
|
|
de-p1st-notify <subject> <body>
|
2021-07-22 13:01:18 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
BODY = None
|
|
|
|
subj = None
|
|
|
|
hostname = socket.gethostname()
|
|
|
|
|
|
|
|
if len(argv) > 3:
|
2021-11-23 19:18:38 +01:00
|
|
|
print('execNotify>> Expected at most two arguments!', file=stderr)
|
2021-07-22 13:01:18 +02:00
|
|
|
exit(1)
|
|
|
|
if len(argv) == 2 or len(argv) == 3:
|
|
|
|
subj = argv[1]
|
|
|
|
if len(argv) == 3:
|
|
|
|
BODY = argv[2]
|
|
|
|
|
|
|
|
if subj is None:
|
|
|
|
subj = 'notify'
|
|
|
|
if BODY is None:
|
2021-07-24 16:07:26 +02:00
|
|
|
BODY = stdin.read()
|
2021-07-22 13:01:18 +02:00
|
|
|
|
|
|
|
SUBJECT = f'{hostname} | {subj}'
|
2021-11-23 19:18:38 +01:00
|
|
|
print(SUBJECT)
|
2021-07-22 13:01:18 +02:00
|
|
|
print(BODY)
|
|
|
|
|
|
|
|
mail.sendMailOrWriteToFile(SUBJECT=SUBJECT, BODY=BODY)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|