Skip to content

Instantly share code, notes, and snippets.

@taoliu
Created January 6, 2012 21:20
Show Gist options
  • Save taoliu/1572452 to your computer and use it in GitHub Desktop.
Save taoliu/1572452 to your computer and use it in GitHub Desktop.
SGE script wrapper
#!/usr/bin/env python
import subprocess
import sys
import os
import time
#time_stamp=time.strftime("%y-%m-%d_%H-%M-%S")
time_stamp=str(time.time())
if len(sys.argv) < 2:
sys.stderr.write("Need more parameters: <command> \"<all command options>\" \n")
sys.exit()
main_name = sys.argv[1]
#argvs = []
#for p in sys.argv[2:]:
# if os.path.isfile(p):
# argvs.append( os.path.realpath(p))
# else:
# argvs.append(p)
#options = " ".join(argvs)
options = sys.argv[2]
cwd = os.getcwd()
job_name = main_name + "_" + time_stamp
sge_template = """#!/bin/bash
#$ -N %s
#$ -e /home/foobar/logs/ -o /home/foobar/logs/
#$ -S /bin/bash
#$ -M [email protected]
source /home/foobar/.bashrc
#mkdir -p -m 700 /scratch/foobar/job_%s
cd %s
%s %s &> %s%s.log
""" % (job_name,time_stamp,cwd,main_name,options,"sge_",job_name)
f = open("sge_"+time_stamp+".sh","w")
f.write( sge_template )
f.close()
subprocess.check_call(['qsub','sge_'+time_stamp+'.sh'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment