[torqueusers] Script to extract working directory for running jobs
Bas van der Vlies
basv at sara.nl
Thu Feb 9 01:10:46 MST 2006
Cliff,
You have to install pbs_python, but this is how i would solve it.
================== Script ===================
#!/usr/bin/env python
from PBSQuery import PBSQuery
import re
def main():
# A regulare expression to get PBS_O_WORKDIR
# from jobs Variable list
#
workdir_re = re.compile(r"""
(?P<WORKDIR>PBS_O_WORKDIR[^,]+)
""", re.VERBOSE)
p = PBSQuery()
l = ['job_state', 'Variable_List']
jobs = p.getjobs(l)
for name,job in jobs.items():
if job.is_running():
result = workdir_re.search(job['Variable_List'])
if result:
print name, result.group('WORKDIR')
main()
=======================================================================
Cliff Kirby wrote:
> I wrote the following script to extract the working directory path from all
> the running jobs in the PBS queue but it will not work when the
> PBS_O_WORKDIR is not on one line by itself. Is there an easier way to get
> just the working directory from all the running jobs from a script? Or
> could someone else share their thoughts on ways I could improve this?
>
> Thanks!
>
> ----------------------------------------------------------------
> #!/bin/bash
>
> QSTATRUNNING=/tmp/qstatrun.out
> QSTATFULL=/tmp/qstatfull.out
>
> # Check Return Code of qstat command
> /opt/torque/bin/qstat -r 1>$QSTATRUNNING
>
> if [ "$?" -ne "0" ]
> then
> echo "****************************"
> echo "** QSTAT command failed!! **"
> echo "****************************"
> else
> clear
> while IFS="." read jobid ignore
> do
> /opt/torque/bin/qstat -f $jobid 1>$QSTATFULL 2>&1
> if [ "$?" -eq "0" ]
> then
> if [[ -n $jobid ]]
> then
> PBSWORKDIR=`qstat -f $jobid | grep
> PBS_O_WORKDIR`
> PBSPATH=`echo ${PBSWORKDIR:15}`
> echo -e "-------- job $jobid in working path
> ${PBSPATH%,*}"---------"
> fi
> fi
>
> done < $QSTATRUNNING # I/O redirection.
> fi
>
> rm $QSTATRUNNING
> rm $QSTATFULL
> #END OF SCRIPT
>
> ------------------------------------------------------------------
>
> _______________________________________________
> torqueusers mailing list
> torqueusers at supercluster.org
> http://www.supercluster.org/mailman/listinfo/torqueusers
--
--
********************************************************************
* *
* Bas van der Vlies e-mail: basv at sara.nl *
* SARA - Academic Computing Services phone: +31 20 592 8012 *
* Kruislaan 415 fax: +31 20 6683167 *
* 1098 SJ Amsterdam *
* *
********************************************************************
More information about the torqueusers
mailing list