-
Notifications
You must be signed in to change notification settings - Fork 1
/
tell_me_about_it.sh
executable file
·56 lines (48 loc) · 1.51 KB
/
tell_me_about_it.sh
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
#!/usr/bin/env python
import sys
import os
import subprocess
from ConfigParser import SafeConfigParser
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import socket
MAIL_TO = ""
MAIL_FROM = ""
def _send_email(subject, body, parser):
MAIL_TO = parser.get("MAIL", "mail_to")
MAIL_FROM = parser.get("MAIL", "mail_from")
MAIL_SERVER = parser.get("MAIL", "mail_server")
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = MAIL_FROM
msg['To'] = MAIL_TO
msg.attach(MIMEText(str(body), 'plain'))
#print msg
smtp = smtplib.SMTP(parser.get("MAIL", "mail_server"),
parser.get("MAIL", "mail_port"))
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
try:
password = parser.get("MAIL", "password")
smtp.login(parser.get("MAIL", "login"), password)
except:
pass
smtp.sendmail(MAIL_FROM, MAIL_TO.split(), msg.as_string())
smtp.close()
def _startjob(args):
"""Start up a job"""
print(args)
ret_val = subprocess.call(args)
return ret_val
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Need a command to run")
exit(1)
parser = SafeConfigParser()
parser.read(os.path.expanduser('~/shellGrease.ini'))
args = sys.argv[1:]
print(_startjob(args))
body = "The following command \n-----\n%s>%s\n-----\nreturned:%s"%(socket.gethostname(), ' '.join(args), _startjob(args))
_send_email("Finished processing", body, parser)