[Toolserver-l] Submitting Python jobs to SGE from cron

Russell Blau russblau at imapmail.org
Thu Jan 6 17:32:16 UTC 2011


Since a number of users seem to be struggling with the conversion to 
Solaris, I thought I would share the scripts I have been using to start my 
Python bots from Solaris cron using the job server.  If you want to use 
these, be sure to substitute your username for "username" in the last line 
of listing 1, and your python path (if you have one defined) in the third 
line of listing 2.

With these scripts in your home directly, you can then set up a cron job to 
run any Python script using the following syntax in your crontab:

 30  9   *   *   *    $HOME/pysub jobname $HOME/path/script.py arg1 arg2

"jobname" is an arbitrary name to be given to the job.  Be sure to include 
$HOME/ in both places; replace /path/ with the path from your home directory 
to the Python script.

I don't know as much about bash as I do about Python, so it is very possible 
someone else can improve on these scripts.  :-)  But feel free to use them 
if they are helpful.

Russ

Listing 1: pysub

 #! /bin/ksh
 # like cronsub, but runs a python script instead of a shell script
 . /sge62/default/common/settings.sh
 [[ $# -ge 1 ]] || {
        echo >&2 "usage: $0 <jobname> <script>"
        exit 1
 }
 JOBNAME=$1
 shift
 SCRIPT=$@
 qstat -j $JOBNAME >/dev/null 2>&1 || qsub -N $JOBNAME /home/username/py.sh 
$SCRIPT >/dev/null

Listing 2: py.sh

 #!/bin/sh
 # run an arbitrary Python script
 PYTHONPATH=/copy/of;/your/pythonpath
 export PYTHONPATH
 /usr/bin/python $@




More information about the Toolserver-l mailing list