def _writeJobScript(statement, job_memory, job_name, shellfile): # disabled - problems with quoting # tmpfile.write( '''echo 'statement=%s' >> %s\n''' % # (shellquote(statement), shellfile) ) # module list outputs to stderr, so merge stderr and stdout script = '''#!/bin/bash\n echo "%(job_name)s : START -> ${0}" >> %(shellfile)s set | sed 's/^/%(job_name)s : /' &>> %(shellfile)s module list 2>&1 | sed 's/^/%(job_name)s: /' &>> %(shellfile)s hostname | sed 's/^/%(job_name)s: /' &>> %(shellfile)s cat /proc/meminfo | sed 's/^/%(job_name)s: /' &>> %(shellfile)s echo "%(job_name)s : END -> ${0}" >> %(shellfile)s ''' % locals() # restrict virtual memory # Note that there are resources in SGE which could do this directly # such as v_hmem. # Note that limiting resident set sizes (RSS) with ulimit is not # possible in newer kernels. script += "ulimit -v %i\n" % IOTools.human2bytes(job_memory) script += expandStatement(statement, ignore_pipe_errors=ignore_pipe_errors) script += "\n" job_path = getTempFilename(dir=PARAMS["workingdir"]) with open(job_path, "w") as script_file: script_file.write(script) return(job_path)
def _writeJobScript(statement, job_memory, job_name, shellfile): # disabled - problems with quoting # tmpfile.write( '''echo 'statement=%s' >> %s\n''' % # (shellquote(statement), shellfile) ) # module list outputs to stderr, so merge stderr and stdout script = '''#!/bin/bash -e \n echo "%(job_name)s : START -> ${0}" >> %(shellfile)s set | sed 's/^/%(job_name)s : /' &>> %(shellfile)s set +o errexit module list 2>&1 | sed 's/^/%(job_name)s: /' &>> %(shellfile)s set -o errexit hostname | sed 's/^/%(job_name)s: /' &>> %(shellfile)s cat /proc/meminfo | sed 's/^/%(job_name)s: /' &>> %(shellfile)s echo "%(job_name)s : END -> ${0}" >> %(shellfile)s ''' % locals() # restrict virtual memory # Note that there are resources in SGE which could do this directly # such as v_hmem. # Note that limiting resident set sizes (RSS) with ulimit is not # possible in newer kernels. script += "ulimit -v %i\n" % IOTools.human2bytes(job_memory) script += expandStatement(statement, ignore_pipe_errors=ignore_pipe_errors) script += "\n" job_path = getTempFilename(dir=PARAMS["workingdir"]) with open(job_path, "w") as script_file: script_file.write(script) return (job_path)
def buildJobScript(statement, job_memory, job_name): '''build job script from statement. returns (name_of_script, stdout_path, stderr_path) ''' tmpfile = getTempFile(dir=PARAMS["workingdir"]) # disabled: -l -O expand_aliases\n" ) tmpfile.write("#!/bin/bash\n") tmpfile.write( 'echo "%s : START -> %s" >> %s\n' % (job_name, tmpfile.name, shellfile)) # disabled - problems with quoting # tmpfile.write( '''echo 'statement=%s' >> %s\n''' % # (shellquote(statement), shellfile) ) tmpfile.write("set | sed 's/^/%s : /' &>> %s\n" % (job_name, shellfile)) # module list outputs to stderr, so merge stderr and stdout tmpfile.write("module list 2>&1 | sed 's/^/%s: /' &>> %s\n" % (job_name, shellfile)) tmpfile.write("hostname | sed 's/^/%s: /' &>> %s\n" % (job_name, shellfile)) tmpfile.write("cat /proc/meminfo | sed 's/^/%s: /' &>> %s\n" % (job_name, shellfile)) tmpfile.write( 'echo "%s : END -> %s" >> %s\n' % (job_name, tmpfile.name, shellfile)) # restrict virtual memory # Note that there are resources in SGE which could do this directly # such as v_hmem. # Note that limiting resident set sizes (RSS) with ulimit is not # possible in newer kernels. tmpfile.write("ulimit -v %i\n" % IOTools.human2bytes(job_memory)) tmpfile.write( expandStatement( statement, ignore_pipe_errors=ignore_pipe_errors) + "\n") tmpfile.close() job_path = os.path.abspath(tmpfile.name) stdout_path = job_path + ".stdout" stderr_path = job_path + ".stderr" os.chmod(job_path, stat.S_IRWXG | stat.S_IRWXU) return (job_path, stdout_path, stderr_path)