From: Greg Ercolano <erco@(email surpressed)> Subject: [Q+A] Rush "donemail" -- how do I send Rush reports in a fixed width Date: Mon, 04 May 2015 15:11:11 -0400 |
Msg# 2393 View Complete Thread (2 articles) | All Threads Last Next |
|
From: Greg Ercolano <erco@(email surpressed)> Subject: Re: [Q+A] Rush "donemail" -- how do I send Rush reports in a fixed Date: Mon, 13 Jul 2015 16:11:11 -0400 |
Msg# 2399 View Complete Thread (2 articles) | All Threads Last Next |
On 05/04/15 12:11, Greg Ercolano wrote: > As a simple example, let's say you want a script to email the > 'rush -lj', 'rush -lfi' and 'rush -lf' reports "To:" prod@your.dom, > and have the message be "From:" rush@your.dom.. > > [perl script snipped] And here's the functionally of that same script, but written in python: ______________________________________________________________________ snip #!/usr/bin/env python -B ''' SEND EMAIL TO USER(S) WHEN JOB IS DONE Invoke this script via 'jobdonecommand'. Any arguments are treated as email addresses to send email message to. 03/31/15 erco@(email surpressed) 1.0 - initial implementation with html formatting 07/12/15 erco@(email surpressed) 1.1 - python port, added links to LogDir ''' import os,sys def HtmlEscapeCommand(cmd): ''' Run a command and html-escape all its output $1 - command to run Returns a multiline string of the command's output, html-escaped. ''' out = "" try: p = os.popen(cmd, "r") except (IOError, os.error), emsg: raise RuntimeError("popen(%s): %s" % (cmd,emsg)) while (True): line = p.readline() if not line: break line = line.replace("&", "&") line = line.replace("<", "<") line = line.replace(">", ">") out += line return out ### ### MAIN ### if os.path.exists("c:/rush"): rushdir = "c:/rush" else: rushdir = "/usr/local/rush" rushsendmail = rushdir + "/etc/bin/rushsendmail" mailfrom = "rush@your.dom" # Parse "To:" addresses from argument list.. mailto = "" for i in range(1, len(sys.argv)): if mailto == "": mailto += sys.argv[i] else: mailto += ", " + sys.argv[i] jobid = os.environ["RUSH_JOBID"] # USE RUSHSENDMAIL TO DELIVER EMAIL # See 'rushsendmail -help' for more info. # You can replace this with a perl module or SSL based mail transports.. # mail = os.popen("%s -t -f%s -p25" % (rushsendmail, mailfrom), "w") # Mail header that enables HTML content mail.write("To: %s\n" % mailto +"From: %s\n" % mailfrom +"Subject: Rush Job: %s DONE\n" % jobid +"MIME-Version: 1.0\n" # how to do.. +"Content-Type: text/html\n" # ..the html formatting. +"Content-Disposition: inline\n" +"\n" # empty line ends header +"<html><body><pre style='font:monospace'>\n" # start html content, use pre-formatted monospace ) # Mail message # Since this is HTML content, any "uncontrolled" content must be HTML escaped # to prevent HTML special characters (&, <, >) from being mistaken as HTML tags.. # mail.write("<B>--- Frame Info Report</B>\n" +HtmlEscapeCommand("rush -lfi %s" % jobid) + "\n" ) mail.write("<B>--- Frames Report</B>\n" +HtmlEscapeCommand("rush -lf %s" % jobid) + "\n" ) mail.write("<B>--- Job Report</B>\n" +HtmlEscapeCommand("rush -ljf %s" % jobid) + "\n" ) mail.write("</pre>\n</body>\n</html>\n") # ends html content # Done mail.close() sys.exit(0) ______________________________________________________________________ snip To use it, name it /yourserver/rushscripts/jobdonescript.py and when you submit the job, you can have it run when the job finishes rendering the last frame with: rush -submit << EOF .. jobdonecommand python /yourserver/rushscripts/jobdonescript.py you@your.dom render_folks@your.dom .. EOF |